0 votes
1 view
in R Programming by (6.5k 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
by (25.3k points)
  • qplot is the simplest choice if you are dealing with input vectors
  • ggplot requires a data.frame as an input data structure.

For example:

a<-1:20

b<-rnorm(20)

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

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...