Adding group mean lines to geom_bar plot and including in legend

人盡茶涼 提交于 2019-11-29 11:25:09

To get the legend for the geom_error you need to pass the colour argument in the aes. As you want only one category (here red), I've create a dummy variable first

df$mean <- "Mean"
ggplot(df, aes(x=factor(Age), y=prop, fill=factor(V1))) +
  geom_bar(position=position_dodge(), colour='black',stat="identity") +
  geom_errorbar(aes (ymax=groupmeans, 
                ymin=groupmeans, colour=mean), lwd=2) +
  scale_colour_manual(name="",values = "#ff0000")

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