Brook's homepage Statistics 306, Fall 2017

Lab 2, September 19

Exercise 1

To test your knowledge of ggplot geoms, complete Exercise 3.6.1 Number 6 from the textbook. You are asked to recreate the following plots using the mpg data frame.

Exercise 2

Background

This exercise allows you to practice statistical transformations and position adjustments in ggplot. We will use the ChickWeight data set, which is automatically loaded when you start an R session.

Run the command ?ChickWeight to learn about how the data were collected.

We would like to understand how the different diets affected the chicks’ weight over time.

Let’s start by plotting the growth trajectory of each chick over time.

ggplot(ChickWeight)+
  geom_line(aes(x=Time, y=weight, group=Chick, color=Diet))

It might be easier to compare the four diets by computing the average chick weight at each time point.

Assignment

Recreate the following plot. Each line plots the mean chick weight over time for each diet. The points display the individual chick weights over time.

Hints:

Solutions

Solutions to exercise 1 and 2