Fall 2023, Exam 1

Your name: Bryce Kunschick

Question 1 (50 points)

Fix the code below

library(tidyverse)

url <- ""

t_raw <- tibble(
  x = 1:10,
  labels = c('a', NA, 'c', NA, 'e', 'f', 'f', 'f', 'i', 'j'))

t <- t_raw %>%
  mutate(labels = ifelse(is.na(labels), "unused", labels)) %>% 
  filter(labels != "unused") %>% 
  mutate(x_plus_1 = x + 1) %>% 
  filter(x > 5)

ggplot(data = t) +
  geom_bar(mapping = aes(x = labels),
           fill = 'blue')

Question 2 (50 points)

Use the mpg tibble that is loaded with tidyverse.

Complete the following tasks

# Create a new tibble called m2
#   Show only models of the a4
#   Create a new field called engine. It should be either 'big' 
#     if displ is over 2.0 or 'small' if not.

# Create a plot using geom_point
#   Map at least 3 data points to the dataset using aes
#   Customize at least one property (such as size or shape)
#   Add a title and caption

m2_raw <- mpg

m2 <- m2_raw %>% 
  filter(model == "a4") %>% 
  mutate(engine = ifelse(displ > 2.0, 'big', 'small'))

ggplot(data = m2) +
  geom_point(mapping = aes(x = jitter(displ), y = hwy),
             color = "blue",
             alpha = .6,
             size = 3) +
  labs(title = "Displacement and Highway Mileage",
       caption = "Audi A4 Model")