Created
August 18, 2021 01:37
-
-
Save chasemc/16992e9b2910f6859407c31279cfe195 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(data.table) | |
library(ggplot2) | |
library(gganimate) | |
population <- fread("/Users/chase/Downloads/csvData.csv") # https://worldpopulationreview.com/states | |
population <- population[, c("State", "Pop")] | |
colnames(population) <- c("state", "population") | |
covid <- "https://raw.githubusercontent.com/nytimes/covid-19-data/master/rolling-averages/us-states.csv" | |
covid <- fread(covid) | |
vaccinated <- "https://raw.githubusercontent.com/govex/COVID-19/master/data_tables/vaccine_data/us_data/time_series/people_vaccinated_us_timeline.csv" | |
vaccinated <- fread(vaccinated) | |
colnames(vaccinated)[which(colnames(vaccinated) == "Province_State")] <- "state" | |
colnames(vaccinated)[which(colnames(vaccinated) == "Date")] <- "date" | |
everything <- merge.data.table(covid, population, by = "state") | |
everything <- merge.data.table(everything, vaccinated, by = c("state","date")) | |
everything[, date := as.Date(everything$date)] | |
# NYTIMES data has pop-adjusted but to compare with vaccine data which isn't, we'll use the same population numbers for both | |
# everything[ , perc_full := (People_Fully_Vaccinated + People_Partially_Vaccinated)/population*100] | |
everything[ , perc_full := (People_Fully_Vaccinated)/population*100] | |
everything[, cases100 := cases_avg / population *100000 ] | |
ggplot(everything,aes(x = perc_full, | |
y = cases100)) + | |
geom_point() + | |
xlab("Percent of State's Population That's Fully Vaccinated") + | |
ylab("Covid Cases Per 100,000") + | |
coord_cartesian( xlim=c(0, 100))+ | |
transition_time(date) + | |
ease_aes('linear') + | |
theme(legend.position = "none") + | |
labs(title = 'Date: {frame_time}') | |
a <- ggplot(everything,aes(x = perc_full, | |
y = cases_avg_per_100k)) + | |
geom_text(aes(label=state)) + | |
xlab("Percent of State's Population That's Fully Vaccinated") + | |
ylab("Covid Cases Per 100,000") + | |
coord_cartesian( xlim=c(0, 100))+ | |
transition_time(date) + | |
ease_aes('linear') + | |
theme(legend.position = "none") + | |
labs(title = 'Date: {frame_time}') | |
animate(a, | |
duration = 100, | |
fps = 3) | |
ggplot(everything[date == as.Date("2021-08-16")]) + | |
geom_point(aes(x = perc_full, | |
y = cases_avg_per_100k)) + | |
xlab("Percent of State's Population That's Fully Vaccinated") + | |
ylab("Covid Cases Per 100,000") + | |
coord_cartesian( xlim=c(0, 100)) + | |
theme(legend.position = "none") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment