Graphics Reference
In-Depth Information
c39 d20
2.80 0.2788867 10 0.08819171
c39 d21
2.74 0.9834181 10 0.31098410
c52 d16
2.26 0.4452215 10 0.14079141
c52 d20
3.11 0.7908505 10 0.25008887
c52 d21
1.47 0.2110819 10 0.06674995
The default dodge width for geom_bar() is 0.9, and you'll have to tell the error bars to be
dodged the same width. If you don't specify the dodge width, it will default to dodging by the
width of the error bars, which is usually less than the width of the bars ( Figure 7-15 ):
# Bad: dodge width not specified
ggplot(cabbage_exp, aes(x = Date, y = Weight, fill = Cultivar)) +
geom_bar(position = "dodge" ) +
geom_errorbar(aes(ymin = Weight - se, ymax = Weight + se),
position = "dodge" , width = .2 )
# Good: dodge width set to same as bar width (0.9)
ggplot(cabbage_exp, aes(x = Date, y = Weight, fill = Cultivar)) +
geom_bar(position = "dodge" ) +
geom_errorbar(aes(ymin = Weight - se, ymax = Weight + se),
position = position_dodge( 0.9 ), width = .2 )
Figure 7-15. Left: error bars on a grouped bar graph without dodging width specified; right: with
dodging width specified
NOTE
Notice that we used position="dodge" , which is shorthand for position=position_dodge() , in
the first version. But to pass a specific value, we have to spell it out, as in position_dodge(0.9) .
Search WWH ::




Custom Search