COVID-19

Playing Politics with Human Lives

Could a state’s residents predominant attitude toward wearing masks and reopening the economy influence COVID-19 infection trends? Polling suggests that Republicans and right-leaning independents tend to take the pandemic less seriously than Democrats and left-leaning independents. Take a look at the following chart (updated daily) that shows state-level COVID-19 testing data aggregated according to which presidential candidate won the popular vote within each state in the 2012 election.


For reference, the chart below shows how Minnesota has faired relative to the average of all other states.

R Code

Load dependencies


library(tidyverse)
library(lubridate)
library(covid19us)
library(poliscidata)
library(tidycensus)

Import data


#import data----
##import daily data from the covid19us package
covid19.daily <- get_states_daily()
names(covid19.daily)[names(covid19.daily)=="state"] <- "abb"

##import state data from the poliscidata package
states.poli <- states
states.poli$state <- trimws(as.character(states.poli$state))

##import state population estimates from the tidycensus packages
states.data <- get_estimates(geography="state", product="population", year="2019") %>%
  filter(variable=="POP") %>%
  select(NAME, value) %>%
  rename("state"="NAME",
         "pop2019"="value") %>%
  mutate(state=str_replace_all(state, " ", ""))

states.abb <- as_tibble(data.frame(state=state.name[1:50], abb=state.abb[1:50])) %>%
  mutate(state=str_replace_all(state, " ", ""))

states.join <- merge(states.data, states.abb, by="state")
states.join <- merge(states.join, covid19.daily, by="abb")

##normalize positive tests and increase in positive tests by 2019 state population
states.join$positive.norm <- states.join$positive/states.join$pop2019 * 1E5
states.join$positive_increase.norm <- states.join$positive_increase/states.join$pop2019 * 1E5

states.join <- as_tibble(states.join)

Create tidy data


covid19.tidy <- states.join %>%
  select(obama_win12, positive_increase.norm, date, state) %>%
  pivot_longer(cols=c(obama_win12),
               names_to="election.year",
               values_to="election.winner") %>%
  mutate(election.year=as_factor(election.year)) %>%
  mutate(election.year=recode(election.year,
                              "obama_win12"="2012")) %>%
  filter(election.year=="2012") %>%
  mutate(election.winner=recode(election.winner,
                                "No"="Romney",
                                "Yes"="Obama")) %>%
  mutate(test.month=month.abb[month(date)]) %>%
  filter(!(test.month %in% c("Jan", "Feb"))) %>%
  drop_na() %>%
  mutate(election.winner=as.character(election.winner)) %>%
  group_by(date, election.winner) %>%
  summarize(positive_increase.norm=signif(round(mean(positive_increase.norm),2),3)) %>%
  rename("Date"="date") %>%
  rename("Election_Result_2012"="election.winner") %>%
  rename("Positive_Increase"="positive_increase.norm")

Plot using ggplot2


gg <- ggplot(covid19.tidy, aes(x=Date,
                               y=Positive_Increase, 
                               color=Election_Result_2012)) +
  geom_point() +
  geom_smooth(method="loess", span=0.3, size=0.5) +
  geom_path(size=0.5, linetype="dotted") +
  scale_color_manual(name=NULL, values=c("Blue", "Red")) +
  xlab(NULL) +
  ylab("Daily Increase in Positive Cases per 100,000") +
  labs(title = "Politics, Masks, and Reopening",
       subtitle = "COVID-19 Infection Trends by State in the U.S.")