Graphics Reference
In-Depth Information
To put the labels in the middle of each bar (
Figure 3-25
), there must be an adjustment to the
cumulative sum, and the yofset in
geom_bar()
can be removed:
ce
<-
arrange(cabbage_exp, Date, Cultivar)
# Calculate y position, placing it in the middle
ce
<-
ddply(ce,
"Date"
, transform, label_y
=
cumsum(Weight)
-
0.5
*
Weight)
ggplot(ce, aes(x
=
Date, y
=
Weight, fill
=
Cultivar))
+
geom_bar(stat
=
"identity"
)
+
geom_text(aes(y
=
label_y, label
=
Weight), colour
=
"white"
)