I'm starting to use the great ggplot2
package for plotting in R, and one of the first things I ask myself before each plot is "well, will I use qplot
or ggplot
?"
I understand that qplot
provides a simpler syntax while ggplot
allows maximum features and flexibility, but what is the function you use the most, and do you have some precise use cases for each one ? Do you use mostly qplot
and ggplot
only for complex plots, or do you use ggplot
everytime ?
Thanks for your feedback !
The function qplot() [in ggplot2] is very similar to the basic plot() function from the R base package. It can be used to create and combine easily different types of plots. However, it remains less flexible than the function ggplot(). This chapter provides a brief introduction to qplot(), which stands for quick plot.
The ggplot2 package includes two main functions, quickplot qplot() for fast graphs and the ggplot() function for more detailed, customizable graphs.
You may notice that we sometimes reference 'ggplot2' and sometimes 'ggplot'. To clarify, 'ggplot2' is the name of the most recent version of the package. However, any time we call the function itself, it's just called 'ggplot'.
Description. qplot() is a shortcut designed to be familiar if you're used to base plot() . It's a convenient wrapper for creating a number of different types of plots using a consistent calling scheme.
As for me, if both qplot and ggplot are available, the criterion depends on whether data is stored in data.frame or separate variables.
x<-1:10 y<-rnorm(10) qplot(x,y, geom="line") # I will use this ggplot(data.frame(x,y), aes(x,y)) + geom_line() # verbose d <- data.frame(x, y) qplot(x, y, data=d, geom="line") ggplot(d, aes(x,y)) + geom_line() # I will use this
Of course, more complex plots require ggplot(), and I usually store data in data.frame, so in my experience, I rarely use qplot.
And it sounds good to always use ggplot(). While qplot saves typing, you lose a lot of functionalities.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With