在ggplot2中选择qplot()和ggplot() [英] Choosing between qplot() and ggplot() in ggplot2
问题描述
我开始在R中使用伟大的 ggplot2
包进行绘图,并且在每个绘图之前我问自己的第一件事情是好我会使用 qplot
还是 ggplot
?
我知道 qplot
提供了一个更简单的语法,而 ggplot
允许最大的特性和灵活性,但是什么是函数你使用得最多,你是否有一些精确的用例?你是否只对复杂的情节使用 qplot
和 ggplot
,或者是否使用 ggplot
每次?
感谢您的反馈!
至于我,如果qplot和ggplot都可用,则标准取决于数据是存储在data.frame还是单独的变量。
< code $ x $< -1:10
y< -rnorm(10)
qplot(x,y,geom =line)#我将使用这个
数据帧(x,y)
$ b bgglot(data.frame(x,y),aes(x,y))+ geom_line()#verbose
$ bd < $ b qplot(x,y,data = d,geom =line)
ggplot(d,aes(x,y))+ geom_line()#我将使用这个
当然,更复杂的图需要ggplot(),而且我通常将数据存储在data.frame中,所以根据我的经验,我很少使用qplot。
总是使用ggplot()听起来不错。虽然qplot保存了打字,但是会失去很多功能。
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 !
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.
这篇关于在ggplot2中选择qplot()和ggplot()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!