- I want to explore weight trends over time for the different diets
- Done using the ggplot2 package in only a few lines of code
- I challenge you to try this in Excel!!
library(ggplot2)
#make nicer labels
ChickWeight$Diet <- factor(ChickWeight$Diet,
labels = c("Diet 1", "Diet 2", "Diet 3", "Diet 4"))
ggplot(ChickWeight, aes(x = Time, y = weight)) + facet_grid(. ~ Diet) +
geom_point(aes(color = Chick), alpha = 0.3, size = 1) +
geom_line(aes(color = Chick), alpha = 0.3) +
geom_smooth(method = "loess", size = 1) +
theme(legend.position="none") +
xlab("Time (days)") + ylab("Weight (grams)")