Submission Details

Due date: the homework is due before class on Thursday.

Submission process: submit both the R Markdown file and the corresponding html file on canvas. Please submit both the .Rmd and the .html files separately and do not zip the two files together.


Measles Vaccination Rates

  1. Download the RMarkdown file with these homework instructions to use as a template for your work. Make sure to replace “Your Name” in the YAML with your name.

  2. The data this week comes from The Wallstreet Journal. The data set includes immunization rate data for schools across the U.S. The accompanying article is published here.

library(dplyr)
library(ggplot2)
library(readr)
measles <- read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-02-25/measles.csv')
  1. For how many schools do we have data? How many of these schools recorded their Measles, Mumps, and Rubella (MMR) vaccination rate? Use the variable mmr to answer this question. Only consider schools with a rate > 0 for the remainder of the homework.
## your answer here
  1. Using mutate(), reorder the levels of the variable state according to the median MMR vaccination rate. Then “pipe” your results into ggplot and create box plots of MMR vaccination rates for each state. Map the variable state to color, include the parameter show.legend = FALSE within geom_boxplot(), and flip the coordinates. Interpret.
## your answer here
  1. According to the CDC, 95% of a population needs to be vaccinated to stop the spread of measles and preserve herd immunity. Using mutate() and case_when(), introduce a new variable into the data set mmr_threshold where the value is “above” when mmr is greater than 95 and “below” otherwise. Is there a relationship between the type of school and the proportion of schools that did not reach that threshold? For each type of school, calculate the mean MMR vaccination rate. On how many responses are the averages based? Show these numbers together with the averages. Additionally, calculate the percentage of schools that did not reach that threshold. Arrange your results from greatest percentage to lowest. Comment on your results.
## your answer here
  1. Use dplyr functions to:
## your answer here
  1. Now use the previous data set to draw a scatter plot with the mean MMR rate for each city on the y-axis and the student enrollment on the x-axis and color by the state mean MMR rate. Use the code below as your starting point and add in the necessary aesthetic mappings within ggplot(aes( )). Describe and summarise the chart.
question6_data %>%
  ggplot(aes( )) + 
  geom_hline(yintercept = 95, linetype = "dashed", size = 0.25, color = "grey40") +
  geom_point(size = 2, alpha = .3) +
  scale_color_gradient(low = "red", high = "blue", limits=c(88, 96), oob = scales::squish, 
  guide = guide_colorbar(direction = "horizontal", title.position = "top", 
                        title = "State average immunization rate", barwidth = 15, barheight = 0.25, 
                        ticks = FALSE, title.hjust = 0.5)) +
  theme_minimal() +
  theme(legend.position = "bottom") +
  ggtitle("MMR immunization rates at schools grouped across US cities") +
  labs(subtitle="According to data collected by The Wall Street Journal",
       x = "Student Enrollment", y = "") +
  scale_x_continuous(labels = scales::comma) 
## your answer here