ggplot2 : Plot mean with geom_bar

匿名 (未验证) 提交于 2019-12-03 01:57:01

问题:

I have the following data frame:

test2 

and I am plotting the bar graphs for each label per group using:

ggplot(test2, aes(label, X2, fill=as.factor(groups))) +      geom_bar(position="dodge", stat="identity") 

However, I am cannot seem to be able to find a stat="mean" so I can plot the means on each bar graph instead of the identity.

Thanks for any help.

回答1:

simply use stat = "summary" and fun.y = "mean"

ggplot(test2) +    geom_bar(aes(label, X2, fill = as.factor(groups)),             position = "dodge", stat = "summary", fun.y = "mean") 



回答2:

ggplot2 likes 1 data point for 1 plot point. Create a new data frame with your summary statistics, then plot with stat="identity"

require(reshape2) plot.data 



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!