2016-12-05 199 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")