Created
June 24, 2020 20:01
-
-
Save gshotwell/eee735144ca970dd738e3ed64f66b2c9 to your computer and use it in GitHub Desktop.
This file contains 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(tidyverse) | |
library(rgeos) | |
library(RcppRoll) | |
library(rworldmap) | |
data <- read_csv("https://covid.ourworldindata.org/data/owid-covid-data.csv") %>% | |
filter(location != "World") | |
plot_df <- data %>% | |
group_by(iso_code) %>% | |
arrange(date) %>% | |
mutate(rolling_deaths = roll_sum(new_deaths, 7, align = "right", fill = NA), | |
rolling_cases = roll_sum(new_cases, 7, align = "right", fill = NA), | |
lagged_rolling_cfr = rolling_deaths / lag(rolling_cases, 14)) %>% | |
filter(date > lubridate::mdy("03-01-2020")) | |
plot_df %>% | |
filter(iso_code %in% c("USA")) %>% | |
filter(date > lubridate::ymd("2020-04-01")) %>% | |
filter(lagged_rolling_cfr < 1) %>% | |
ggplot(aes(x = date, y = lagged_rolling_cfr, facets = location, | |
colour = rolling_deaths)) + | |
geom_point() + | |
theme_light() + | |
scale_y_continuous(labels = scales::percent) + | |
scale_color_viridis_c() + | |
labs(title = "USA Covid Death Rate", | |
subtitle = "Deaths divided by cases 14 days prior", | |
colour = "Deaths previous 7 days") + | |
xlab("Date") + | |
ylab("14 day lagged CFR") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment