简体   繁体   English

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

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

I've a problem. 我有问题 I use for my error bars the standard error (se). 我为我的误差线使用标准误差(se)。 My error bars are far above my bars and I've tried already placing the ymin and ymax in ggplot itself, but with no effect. 我的误差线远高于误差线,我已经尝试将ymin和ymax放置在ggplot中,但没有任何效果。

My data frame looks like the following: 我的数据框如下所示:

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

And I used the following code: 我使用了以下代码:

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)

I don't know why the position of the error_bars ends up so much higher than the bars itself. 我不知道为什么error_bars的位置最终比条形图本身高得多。

I would appriciate your help, many thanks! 谢谢您的帮助,非常感谢!

It seems to be something with setting y as factor. 将y设置为因子似乎有些问题。 If you remove it, it works: 如果删除它,它将起作用:

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