Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Use geom_bar() and map a
variable fill. This will put Date on the x-axis and use Cultivar for the fill color, as shown in Figure 3-16:
library(gcookbook)# For the data setggplot(cabbage_exp,aes(x=Date,y=Weight,fill=Cultivar))+geom_bar(stat="identity")
To understand how the graph is made, it’s useful to see how the
data is structured. There are three levels of Date and two levels of Cultivar, and for each combination there is a
value for Weight:
cabbage_exp
Cultivar Date Weight sd n se
c39 d16 3.18 0.9566144 10 0.30250803
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