繁体   English   中英

ggplot2错误条在条上的位置错误

[英]ggplot2 wrong position of error bars over the bars

我有问题 我为我的误差线使用标准误差(se)。 我的误差线远高于误差线,我已经尝试将ymin和ymax放置在ggplot中,但没有任何效果。

我的数据框如下所示:

  ID variable        se
1 A  14.340695 0.7917790
2 B  32.506312 0.9092173
3 C  7.279953 0.0444325

我使用了以下代码:

df$variable=as.numeric(as.character(df$variable))
limits<-aes(ymin=df$variable - df$se, ymax=df$variable + df$se)
r<-ggplot(df, aes(x=ID, y=factor(variable), fill=variable)) 
r + geom_bar(position=position_dodge(), stat="identity") + geom_errorbar(limits)

我不知道为什么error_bars的位置最终比条形图本身高得多。

谢谢您的帮助,非常感谢!

将y设置为因子似乎有些问题。 如果删除它,它将起作用:

ggplot(df, aes(x=ID, y=variable, fill=variable)) + 
  geom_bar(stat="identity") +
  geom_errorbar(aes(ymin=variable-se, ymax=variable+se))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM