R 使用ggplot2在条形图中放置错误条

R 使用ggplot2在条形图中放置错误条,r,ggplot2,R,Ggplot2,嗨,我在RStudio中使用ggplot版本0.9.3.2,我正在尝试用错误条绘制条形图。问题在于错误条的位置错误。我需要把它们放在各个酒吧的顶部 我有一个这样的数据框 concentration variable value sd 1 0 AF_B 0.3567126 0.010391001 2 0.5x AF_B 0.3355766 0.003480245 3 1x

嗨,我在RStudio中使用ggplot版本0.9.3.2,我正在尝试用错误条绘制条形图。问题在于错误条的位置错误。我需要把它们放在各个酒吧的顶部

我有一个这样的数据框

   concentration variable     value          sd
1              0     AF_B 0.3567126 0.010391001
2           0.5x     AF_B 0.3355766 0.003480245
3             1x     AF_B 0.3001138 0.009104821
4             5x     AF_B 0.2658911 0.016312390
5            10x     AF_B 0.2115522 0.011056590
6           100x     AF_B 0.2655958 0.015092367
7              0      D_B 0.3567126 0.010391001
8           0.5x      D_B 0.3453078 0.011639252
9             1x      D_B 0.3380180 0.004357810
10            5x      D_B 0.3349004 0.018119644
11           10x      D_B 0.3186451 0.014515436
12          100x      D_B 0.3174700 0.016685932
我有以下代码

    dodge = position_dodge(width=0.9)
    c = ggplot(data=dm, aes(y=value,x=concentration))
    c + geom_bar(position = dodge, 
         stat="identity",
         aes(fill=variable,colour=variable,group=variable, colour="black")) +
    geom_errorbar(aes(ymin=value-sd,ymax=value+sd),
          position=dodge,
          width=0.1,
          size=0.3) +
    ylab("mu_max [h-1]") +
    scale_x_discrete(limits=c("0","0.5x","1x","5x","10x","100x"))
,给了我这个情节,很明显


您应该在
ggplot()
调用中移动参数
fill=variable
,以确保
geom\u errorbar()
也使用
variable
作为回避变量

ggplot(data=dm,aes(y=value,x=concentration,fill=variable))+
  geom_bar(position = position_dodge(), 
           stat="identity") +
  geom_errorbar(aes(ymin=value-sd,ymax=value+sd),
                position=dodge,width=0.1,size=0.3)+
  ylab("mu_max [h-1]") +
  scale_x_discrete(limits=c("0","0.5x","1x","5x","10x","100x"))