Skip to content

Instantly share code, notes, and snippets.

@reuning
Created July 31, 2021 23:16
Show Gist options
  • Save reuning/ac4f448b7df2e61a3964fc7f8270c60f to your computer and use it in GitHub Desktop.
Save reuning/ac4f448b7df2e61a3964fc7f8270c60f to your computer and use it in GitHub Desktop.
Plot of vaccination vs Biden support with outliers higlighted
setwd("~/Downloads/")
library(ggplot)
library(ggrepel)
library(data.table)
df <- fread("https://data.cdc.gov/resource/8xkx-amqh.csv")
df_election <- fread("countypres_2000-2020.csv") # https://dataverse.harvard.edu/dataset.xhtml?persistentId=doi:10.7910/DVN/42MVDX
df_election <- df_election[year==2020 & party == "DEMOCRAT" & mode=="TOTAL"]
df_election[,prop:=100*candidatevotes/totalvotes]
df[,fips:=as.numeric(fips)]
all <- merge(df, df_election, by.x="fips",by.y="county_fips")
all <- all[!is.na(fips)]
all <- all[series_complete_18pluspop!=0]
mod <- lm(series_complete_18pluspop~ prop, data=all)
all$res <- mod$residuals
ggplot(all, aes(x=prop, y=series_complete_18pluspop)) + geom_point(alpha=.5) +
theme_minimal() + geom_smooth(method = "lm") +
geom_text_repel(aes(label=paste0(recip_county, ", ", recip_state)),
data = all[res>20] ) + labs(y="Pop Over 18 Vaccinated",
x="Vote for Biden")
ggplot(all, aes(x=prop, y=series_complete_18pluspop)) + geom_point(alpha=.5) +
theme_minimal() + geom_smooth(method = "lm") +
geom_text_repel(aes(label=paste0(recip_county, ", ", recip_state)),
data = all[res<(-20)] ) + labs(y="Pop Over 18 Vaccinated",
x="Vote for Biden")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment