Single error bar on stacked bar plot ggplot

青春壹個敷衍的年華 提交于 2019-12-01 11:13:53

You can create a Dummy data set (i did it with data.table package) that will compute the mean(se) (although I don't think it's the best practice) and plot it as following (I've changed the color of the error bars so you could see them better)

dodge<- position_dodge(width = 0.65)
cols <- c(Top="darkgrey",Bottom="lightgrey", Well_plate="white") 
library(data.table)
Dummy <- data.table(df)[, list(Rate = sum(Rate), se = mean(se), Or = "WP"), by = c("Sp", "Type")] 
ggplot(df,aes(x=factor(Type),y=Rate,fill=factor(Or))) +
  geom_bar(aes(width=.65), stat="identity",colour="black")+
  geom_errorbar(data = Dummy, aes(ymax = Rate +se, ymin=  Rate -se), position="dodge", colour="red", width=.65)+
  scale_fill_manual(values = cols)+
  facet_grid(. ~ Sp)

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