Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Choosing between qplot() and ggplot() in ggplot2 [closed]

Tags:

r

ggplot2

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 !

like image 234
juba Avatar asked Mar 16 '11 08:03

juba


People also ask

What is the difference between Qplot and ggplot?

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.

Is Qplot part of ggplot2?

The ggplot2 package includes two main functions, quickplot qplot() for fast graphs and the ggplot() function for more detailed, customizable graphs.

What is the difference between ggplot and ggplot?

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'.

What does Qplot do in R?

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.


1 Answers

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.

like image 172
kohske Avatar answered Sep 20 '22 20:09

kohske