问题描述
我想绘制误差线和带状阴影区域以标记误差线值的平均值:
出于某种原因,我无法让 geom_errorbar 和 geom_ribbon 一起工作。示例代码:
group <- c("Group 1","Group 1","Group 2","Group 3","Group 4","Group 4")
subgroup <- c("High","Low","High","Low")
value <- c(0.1,-0.1,0.4,0.5,0.25,0.6,-0.25,0.05)
sd <- c(0.1,0.1,0.05,-0.05,-0.01,-0.01)
value_avg <- c(0.33,0.33,0.33)
sd_avg <- c(0.07,0.07,0.07)
df <- data.frame(group,subgroup,value,sd)
#Plot
ggplot(df,aes(group,value)) +
geom_errorbar(
aes(ymin = value-sd,ymax = value+sd,color = subgroup),position = position_dodge(0.3),width = 0.3
)+
geom_point(aes(color = subgroup),position = position_dodge(0.3))+
geom_ribbon(aes(ymin = value_avg-sd_avg,ymax = value_avg+sd_avg),fill = "grey70")
编辑 1:显示 Stefan 的建议:
geom_ribbon(aes(ymin = value_avg-sd_avg,ymax = value_avg+sd_avg,group = 1)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)