What is the difference between the qplot() function and the ggplot() function from the ggplot2 package in R?

r
datavisualization
ggplot2

#1

Hello,

I read that we can use the qplot() and the ggplot() functions to get the same plots in R.
For example->

library(ggplot2)

ggplot(diamonds, aes(clarity,fill=cut)) +geom_bar()
qplot(clarity,fill=cut,data=diamonds,geom=“bar”)

Both of the above commands give the exact same plot->

What exactly is the difference between these functions?

Thanks.


#2

more complex plot requires ggplot(), if both qplot and ggplot are available, the criterion depends on whether data is stored in data.frame or separate variables.

And it sounds good to always use ggplot(), because using qplot only save your type but lose many functionalities.