Proportional Stacked Bar Graph

Want to learn more? I recommend working through: R for Data Science, R Cookbook, and R Graphics Cookbook.

# load the ggplot2 package

# load the gcookbook package

# load the plyr package
# do dataframe to dataframe apply. split up cabbage_exp by "Date" (there are three dates), and create a new variable which is percent_weight
ce <- ddply(cabbage_exp, "Date", transform, percent_weight = Weight / sum(Weight) * 100)
# create a ggplot data object of date, percent_weight, and filled by cultivar
ggplot(ce, aes(x=Date, y=percent_weight, fill=Cultivar)) +
  # plot the bars that are black
  geom_bar(stat="identity", colour="black") +
  # reserve the legend so it matches the colors
  guides(fill=guide_legend(reverse=TRUE)) +
  # fill with the pastel1 color palette