ggplot is one of statistical package that facilitates the easy creation of different plots. One of the key concept related to ggplot is that ggplot is built up layer by layer. This means that one could start by initializing the ggplot using ggplot(data) command and then, keep adding on plot functions as another layer in order to finally draw the plot/chart. The layers are separated by “+” sign. Following is a sample ggplot command created using diamonds data that gets loaded by default when loading ggplot.
ggplot(data=diamonds, aes(x=carat, y=price)) + geom_point(aes(color=color)) + xlab("Carat") + ylab("Price") + ggtitle("Carat vs Price")
Following is the plot for above command:
Before going further, lets quickly see what would it take to install and load ggplot2 package.
Following are some key concepts to know when starting with ggplot:
ggplot(data=diamonds)
aes(x,y)
One must note that aes function could either go in ggplot function such as following or in one of the geom functions.
# aes function within ggplot function
ggplot(data=diamonds, aes(x=carat, y=price)) + geom_point() + xlab("Carat") + ylab("Price") + ggtitle("Carat vs Price")
# aes function within geom function
ggplot(data=diamonds) + geom_point(aes(x=carat, y=price)) + xlab("Carat") + ylab("Price") + ggtitle("Carat vs Price")
Last updated: 3rd May, 2024 Have you ever wondered why some machine learning models perform…
Last updated: 2nd May, 2024 The success of machine learning models often depends on the…
When working on a machine learning project, one of the key challenges faced by data…
Last updated: 1st May, 2024 The bias-variance trade-off is a fundamental concept in machine learning…
Last updated: 1st May, 2024 As a data scientist, understanding the nuances of various cost…
Last updated: 1st May, 2024 In this post, you will learn the concepts related to…