You can download this .qmd file from here. Just hit the Download Raw File button.

Determinants of COVID vaccination rates

A recent Stat 272 project examined determinants of covid vaccination rates at the county level. Our data set contains 3053 rows (1 for each county in the US) and 14 columns; here is a quick description of the variables we’ll be using:

  1. Consider only Minnesota and its surrounding states (Iowa, Wisconsin, North Dakota, and South Dakota). We want to examine the relationship between the percentage who voted for Biden and the percentage of complete vaccinations by state. Generate two plots to examine this relationship:
  1. A scatterplot with points and smoothers colored by state. Make sure the legend is ordered in a meaningful way, and include good labels on your axes and your legend. Also leave off the error bars from your smoothers.

{r; warning = FALSE, message = FALSE} vaccine_data |> filter(state == "Minnesota" | state == "Iowa" | state == "Wisconsin" | state == "North Dakota" | state == "South Dakota") |> mutate(state = fct_reorder2(state, perc_Biden, perc_complete_vac)) |> ggplot(aes(x = perc_Biden, y = perc_complete_vac, color = state)) + geom_point() + geom_smooth(se = FALSE) + labs( x = "Percent of County Voted Biden (2020)", y = "P ercent of County Completely Vaccinated (2020)", color = "State County Is In" )

  1. One plot per state containing a scatterplot and a smoother.

{r; warning = FALSE, message = FALSE} vaccine_data |> filter(state == "Minnesota" | state == "Iowa" | state == "Wisconsin" | state == "North Dakota" | state == "South Dakota") |> ggplot(aes(x = perc_Biden, y = perc_complete_vac)) + geom_point() + geom_smooth(se = FALSE) + facet_wrap(~state) + labs( x = "Percent of County Voted Biden (2020)", y = "Percent of County Completely Vaccinated (2020)" )

Describe which plot you prefer and why. What can you learn from your preferred plot?

I think that I prefer the second graph. I like that there is less of a cluster so I can more easily see the entire trend line for each state. In my opinion, the only thing that is nicer about the first graph is that it is easier to compare the extremes to the other states. From my preferred plot I can more easily see the relationship between the percent of the county that voted for Biden and the percent of the county that was completely vaccinated per state. It is easier to see that Iowa, Minnesota, and Wisconsin have a more positive linear relationship while South Dakota’s trend is more curved but still positive. North Dakota has more variety in its trend.

  1. We wish to compare the proportions of counties in each region with median household income above the national median ($69,560).
vaccine_data |>
  group_by(state) |>
  summarize(prop_above_median = mean(median_HHincome_2019 > 69560, na.rm = TRUE))
## # A tibble: 51 × 2
##    state                prop_above_median
##    <chr>                            <dbl>
##  1 Alabama                         0.0149
##  2 Alaska                          0.5   
##  3 Arizona                         0     
##  4 Arkansas                        0.0133
##  5 California                      0.46  
##  6 Colorado                        0.375 
##  7 Connecticut                     0.875 
##  8 Delaware                        0.333 
##  9 District of Columbia            1     
## 10 Florida                         0.0896
## # ℹ 41 more rows
  1. Fill in the blanks below to produce a segmented bar plot with regions ordered from highest proportion above the median to lowest.

  2. Create a table of proportions by region to illustrate that your bar plot in (a) is in the correct order (you should find two regions that are really close when you just try to eyeball differences).

  3. Explain why we can replace fct_relevel(region, FILL IN CODE) with

mutate(region_sort = fct_reorder(region, median_HHincome_2019 < 69560, .fun = mean))

but not

mutate(region_sort = fct_reorder(region, median_HHincome_2019 < 69560))

vaccine_data |>
  mutate(HHincome_vs_national = ifelse(median_HHincome_2019 < 69560, FILL IN CODE)) |>
  mutate(region_sort = fct_relevel(region, FILL IN CODE)) |>
  ggplot(mapping = aes(x = region_sort, fill = HHincome_vs_national)) +
    geom_bar(position = "fill")
  1. We want to examine the distribution of total county populations and then see how it’s related to vaccination rates.
  1. Carefully and thoroughly explain why the two histograms below provide different plots.
vaccine_data |>
  mutate(tot_pop_millions = tot_pop / 1000000) |>
  ggplot(mapping = aes(x = tot_pop_millions)) +
    geom_histogram(bins = 40) +
    labs(x = "Total population in millions")

vaccine_data |>
  mutate(tot_pop_millions = tot_pop %/% 1000000) |>
  ggplot(mapping = aes(x = tot_pop_millions)) +
    geom_histogram(bins = 40) +
    labs(x = "Total population in millions")

  1. Find the top 5 counties in terms of total population.

  2. Plot a histogram of logged population and describe this distribution.

  3. Plot the relationship between log population and percent vaccinated using separate colors for Metro and Non-metro counties (be sure there’s no 3rd color used for NAs). Reduce the size and transparency of each point to make the plot more readable. Describe what you can learn from this plot.

  1. Produce 3 different plots for illustrating the relationship between the rural_urban_code and percent vaccinated. Hint: you can sometimes turn numeric variables into categorical variables for plotting purposes (e.g. as.factor(), ifelse()).
vaccine_data |>
  ggplot(mapping = aes(x = rural_urban_code, y = perc_complete_vac)) +
  geom_jitter() +
  geom_smooth(method = "lm")
## `geom_smooth()` using formula = 'y ~ x'

vaccine_data |>
  ggplot(mapping = aes(x = as.factor(rural_urban_code),
                       y = perc_complete_vac)) +
  geom_boxplot()

vaccine_data |>
  ggplot(mapping = aes(x = as.factor(rural_urban_code),
                       y = perc_complete_vac)) +
  geom_violin()

State your favorite plot, why you like it better than the other two, and what you can learn from your favorite plot.

I think that my favorite plot of the three is the box plot. I like it better than the violin plot because it makes it easier to compare the distribution. The lines make it very obvious which rural urban codes have the highest median of countys completely vaccinated. It also makes it more obvious which counties are outliers for each rural urban code and since there are many, this is very useful. I think the jitter plot is nice because it does show you all the counties, however, with so many data points it can be a little overwhelming. From the box plot, you can see that the counties that are the least urban also have the highest percentage of their population completely vaccinated, while the most rural had a lower percentage of their population completely vaccinated.

  1. BEFORE running the code below, sketch the plot that will be produced by R. AFTER running the code, describe what conclusion(s) can we draw from this plot?

Conclusions that can be drawn from this plot are that Virginia, Georgia, and North Carolina are the three states that had the most variety in the percentage of people that voted for Biden based on county. Tennessee and Missouri on the other hand had almost the same percentage of people vote for Biden, regardless of which county they lived in.

vaccine_data |>
  filter(!is.na(perc_Biden)) |>
  mutate(big_states = fct_lump(state, n = 10)) |>
  group_by(big_states) |>
  summarize(IQR_Biden = IQR(perc_Biden)) |>
  mutate(big_states = fct_reorder(big_states, IQR_Biden)) |>
  ggplot() + 
    geom_point(aes(x = IQR_Biden, y = big_states))