FiveThirtyEight article (Jun 26, 2020) by Kaleigh Rogers and Nathaniel Rakich
The original article can be found at:
https://fivethirtyeight.com/features/voter-registrations-are-way-way-down-during-the-pandemic/
# Load the tidyverse
library(tidyverse)
# Import data
vreg<-read.csv("https://raw.githubusercontent.com/fivethirtyeight/data/master/voter-registration/new-voter-registrations.csv",
header=TRUE)
# Level the Month variable so that its in the right order (ie not alphabetical)
vreg$Month<-factor(vreg$Month,
levels=c("Jan", "Feb", "Mar", "Apr", "May"))
### USE spread() FROM tidyr
vregYear<-vreg%>%
spread(Year, New.registered.voters)
### RENAME THE COLUMNS
colnames(vregYear)<-c("Jurisdiction", "Month", "Y2016", "Y2020")
### mutate() FROM dplyr()
vregChange<-vregYear%>%
mutate(change=Y2020-Y2016)
vregChange<-vregYear%>%
mutate(change=Y2020-Y2016)%>%
mutate(direction=change>=0)
facet_wrap
The code has been hidden, however, your final graphic should look like this: