ggplot2错误条位置错误

时间:2016-08-04 10:36:27

标签: r ggplot2 errorbar

我有问题。我用我的错误栏标准错误(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的位置比条形本身高得多。

我会恭喜你的帮助,非常感谢!

1 个答案:

答案 0 :(得分:0)

似乎将y设置为因子。如果你删除它,它的工作原理:

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