2016-12-05 206 views
0

我刚刚遇到一个错误,同时使用ggplot2和qplot函数(请参阅下面的警告和错误),我不知道如何进行更改,以便它将工作。我查看了与此问题相关的过去文章,但仍无法更正代码。ggplot2,qplot,关于stat_count()的警告和错误

任何人都可以给我一些建议吗?


> library(ggplot2) 

Warning message: package ‘ggplot2’ was built under R version 3.2.5

> dodge <- position_dodge(width = .9) 

> plot <- qplot(happening, target.looking_M, data=d.c2.subjects, stat="identity", 
+ geom="bar", position=dodge, 
+ ylab="Proportion of looks", xlab="happening", 
+ fill=happening, colour=happening, 
+ main="Proportion target looking by condition and testing phase for each single subject") 

警告消息:

1: `stat` is deprecated 

2: `position` is deprecated 
> plot <- plot + facet_grid(type ~ subjectname) 

> plot 
Error: stat_count() must not be used with a y aesthetic. 
+1

请花时间学习和输入(如有必要,请使用IDE代码段扩展)完整的ggplot2'geom_''s。 (a)您最终会制作更好的图表(b)您将更好地使用您的IDE(c)我花了一些可衡量的时间从ggplot2中移除qplot示例。考虑到你看到的其他一些消息,你应该尽量保持你的R环境(基本二进制R安装和软件包)更平等。 – hrbrmstr

回答

2

正如警告说,以这种方式使用的statqplot已经过时了。作为一般性建议,我会避开qplot,并学习如何使用完整的ggplot语法,因为这会为您提供更多的功能。

为了完成这项工作,您可以改用geom = "col"geom_col是一个新的geom,其行为如geom_bar(stat = "identity")