Boxplot problem created by error bar

Are you just trying to get end caps on the whiskers? If so, see the code below, which is a modification of kjhealy's answer. Note that:

  1. The stat_boxplot and geom_boxplot calls are dodged by the same amount, so that they will align properly.
  2. The width argument in geom_boxplot is set to the same value as the dodging width, so that the dodged boxplots will abut each other. Change to a smaller value if you'd like a little space between the boxplots within each pair.
  3. The width argument to stat_boxplot sets the width of the whisker end caps.
pd = position_dodge(width = 0.5)

ggplot(airquality_trimmed, aes(x = Month, y = Ozone, fill = Temp.f)) +
  stat_boxplot(geom="errorbar", position=pd, width=0.2) +
  geom_boxplot(width=0.5, position=pd)

Rplot

5 Likes