Graphics Reference
In-Depth Information
Solution
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 set
ggplot(cabbage_exp, aes(x = Date, y = Weight, fill = Cultivar)) +
geom_bar(stat = "identity" )
Figure 3-16. Stacked bar graph
Discussion
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 :
Search WWH ::




Custom Search