AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
![]() We firstly save our plot to 'a' and thus we make the alterations. If we want to add some title or sub-title to our graph thus we can use ggtitle( ) where the first argument is our 'main title' and second argument is our subtitle.Ī <- ggplot(mtcars,aes(x = mpg, y = disp, color = factor(cyl))) + geom_point()Ī + labs(color = "Cylinders") + xlab("Mileage") + ylab("Displacement") ![]() Here using labs( ) we can change the title of our legend or ggtitle we can assign our graph some title. Ggplot(mtcars,aes(x = mpg,y = disp)) + geom_point() + ggtitle(label = "Scatter plot", Ggplot(mtcars,aes(x = mpg,y = disp)) + geom_point() + ggtitle(label = "Scatter plot") Ggplot(mtcars,aes(x = mpg,y = disp)) + geom_point() + labs(title = "Scatter plot") Ggplot(data = mtcars, aes(x = mpg,y = disp,colour = hp)) + geom_point(size = 2.5) + geom_line(aes(y = hp)) # Plotting the horsepower using geom_line In a similar way we can use geom_line( ) to plot another line on the graph: geom_smooth( ) is used to determine what kind of pattern is exhibited by the points. In the above command we try to plot mileage (mpg) and displacement (disp) and variation in colors denote the varying horsepower(hp). Ggplot(data = mtcars, aes(x = mpg,y = disp,colour = hp)) + geom_point() + geom_smooth() # Seeing the patterns with the help of geom_smooth. Also factor(cyl) transforms our continuous variable cylinder to a factor. We plot the displacement corresponding to mileage and for different cylinders we are using various colors. We use subset( ) function to select only those cars which have am = 0 paraphrasing it we are considering only those cars which are automatic. Scatter plot denotingvarious levels of cyl Ggplot(data = subset(mtcars,am = 0),aes(x = mpg,y = disp,colour = factor(cyl))) + geom_point() # Creating scatter plot for automatic cars denoting different cylinders. Scatter plots are constructed using geom_point( ) am Transmission (0 = automatic, 1 = manual).In order words, we have 32 observations and 11 different variables: The 'mtcars' data consists of fuel consumption (mpg) and 10 aspects of automobile design and performance for 32 automobiles. We have 3 species of flowers: Setosa, Versicolor and Virginica and for each of them the sepal length and width and petal length and width are provided.Ģ. The 'iris' data comprises of 150 observations with 5 variables. In this article, we will use three datasets - 'iris', 'mpg' and 'mtcars' datasets available in R.ġ. ![]() ![]() Geom_line(), geom_step(), geom_path(), geom_errorbar() Geom_boxplot(), stat_boxplot(), stat_summary() Geom_histogram(), stat_bin(), position_identity(), position_stack(), position_dodge() Geom_point(), geom_smooth(), stat_smooth() The table below shows common charts along with various important functions used in these charts.
0 Comments
Read More
Leave a Reply. |