Last active
March 24, 2020 23:59
-
-
Save chasemc/a8e07156e98640afcbe3a45afefd68f8 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(ggplot2) | |
library(data.table) | |
library(geofacet) | |
library(grid) | |
library(gganimate) | |
# Accessed 2020-03-24 at 9pm CST | |
confirmed <- data.table::fread("http://covidtracking.com/api/states/daily.csv") | |
confirmed$date <- as.Date(as.character(confirmed$date), "%Y%m%d") | |
confirmed <- confirmed[confirmed$date != "2020-03-24", ] | |
save_to <- 'C:/Users/CMC/Desktop/delete' | |
setwd(save_to) | |
p <- ggplot(confirmed) + | |
geom_point(aes(x = date, | |
y = positive), | |
alpha = 0) + | |
theme(plot.title = element_text(hjust = 0.5)) + | |
ylab("Number of Cases") + | |
xlab("Date") + | |
ggtitle("Cumulative Totals of Covid19 by State, March 03 to March 23 (y-axes are different for each state)") + | |
theme(plot.title = element_text(hjust = 0.5)) + | |
theme(axis.text.x = element_blank(), | |
axis.ticks = element_blank()) | |
un_dates <- sort(unique(confirmed$date)) | |
for (i in seq_along(un_dates)){ | |
pp <- p + | |
geom_point(data = confirmed[date <= un_dates[[i]]][state %in% state.abb], | |
aes(x = date, | |
y = positive), | |
alpha = 1) + | |
facet_geo(~ state, | |
grid = "us_state_grid1", | |
label = "name", | |
scales = "free_y") | |
ggsave(filename = paste0(i, ".png"), | |
plot = pp, | |
device = "png", | |
width = 18, | |
height = 10, | |
units = "in") | |
} | |
Author
chasemc
commented
Mar 24, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment