Instructions

I’m looking for your best, not the best. If you turn in nothing, you get no points. If you turn in the bare minimum you will be miles ahead of those who don’t.

If you have difficulty, ask for help. If you feel stressed out, make note of that feeling, check your breathing, and move forward. This semester is not the last time you’ll have that feeling. Your experience of your life will be better if you learn to recognize that feeling rather than run away from it.

Save your work in a file named quiz2_your_name.R. Your script should save your answers into the variables ans1, ans2, ans3, and ans4.

Set up your script as follows:

rm(list=ls())
library(tidyverse)
data(mpg)
# answer variables
ans1 <- numeric(1) # a single number value that your script will update
ans2 <- mpg # a data frame generated from `mpg`
ans3 <- ggplot(mpg) # a plot object made using ggplot
ans4 <- ggplot(mpg)
################################################################################
############################### YOUR WORK BELOW: ###############################
################################################################################

Questions

  1. How many observations are included in the mpg data set?

  2. Find the average city and highway miles per gallon for each manufacturer. Your answer should be a dataframe with columns labelled manufacturer, cty, and hwy.

  3. Generate a graph illustrating the relationship between engine size (i.e. displacement) and city fuel economy.

  4. Modify your graph above to also account for the class of each car.