关于stat_count()的ggplot2,qplot,警告和错误

时间:2016-12-05 10:34:29

标签: r ggplot2

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

有人可以给我一些建议吗?

> 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 个答案:

答案 0 :(得分:2)

正如警告所述,在stat中不推荐使用qplot这种方式。作为一般性建议,我不再依赖于qplot并学习如何使用完整的ggplot语法,因为这样可以为您提供更多功能。

为了完成这项工作,您可以使用geom = "col"代替。 geom_col是一个新的geom,其行为类似于geom_bar(stat = "identity")