Explore Courses Blog Tutorials Interview Questions
0 votes
in R Programming by (7.3k points)

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!

1 Answer

0 votes
  • qplot is the simplest choice if you are dealing with input vectors
  • ggplot requires a data.frame as an input data structure.

For example:



qplot(a,b, geom="line") #Easier to use

ggplot(data.frame(a,b), aes(a,b)) + geom_line() # verbose

df <- data.frame(a,b)

qplot(a, b, data=df, geom="line") 

ggplot(df, aes(a,b)) + geom_line() #Easier to use

More complex plots require ggplot(), and usually data stored in a data.frame, rarely uses qplot.

While qplot saves typing, you lose a lot of functionality.

Related questions

Browse Categories