You can download this .qmd file from here. Just hit the Download Raw File button.
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:
state = state the county is located incounty = name of the countyregion = region the state is located inmetro_status = Is the county considered “Metro” or “Non-metro”?rural_urban_code = from 1 (most urban) to 9 (most rural)perc_complete_vac = percent of county completely vaccinated as of 11/9/21tot_pop = total population in the countyvotes_Trump = number of votes for Trump in the county in 2020votes_Biden = number of votes for Biden in the county in 2020perc_Biden = percent of votes for Biden in the county in 2020ed_somecol_perc = percent with some education beyond high school (but not a Bachelor’s degree)ed_bachormore_perc = percent with a Bachelor’s degree or moreunemployment_rate_2020 = county unemployment rate in 2020median_HHincome_2019 = county’s median household income in 2019{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" )
{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.
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
Fill in the blanks below to produce a segmented bar plot with regions ordered from highest proportion above the median to lowest.
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).
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")
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")
Find the top 5 counties in terms of total population.
Plot a histogram of logged population and describe this distribution.
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.
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.
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))