Home > OS >  Error bars for barplot only in one direction, but for the last one in the opposite direction
Error bars for barplot only in one direction, but for the last one in the opposite direction

Time:03-02

This very useful enter image description here

CodePudding user response:

The solution in the linked question will actually produce this result. You just need to make sure that the standard error is subtracted instead of added when the bar points down:

limits <- aes(ymax = resp   se * sign(resp))

Now your plotting code is pretty much unaltered:

dodge  <- position_dodge(width = 0.9)

ggplot(df, aes(fill = group, y = resp, x = trt))  
  geom_bar(position = dodge, stat = "identity")  
  geom_uperrorbar(limits, position = dodge, width = 0.25)

enter image description here

  • Related