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")
In recent years, artificial intelligence (AI) has evolved to include more sophisticated and capable agents,…
Adaptive learning helps in tailoring learning experiences to fit the unique needs of each student.…
With the increasing demand for more powerful machine learning (ML) systems that can handle diverse…
Anxiety is a common mental health condition that affects millions of people around the world.…
In machine learning, confounder features or variables can significantly affect the accuracy and validity of…
Last updated: 26 Sept, 2024 Credit card fraud detection is a major concern for credit…