library(tidyverse)
library(anytime)
# Data Repo Johns Hopkins CSSE
# https://github.com/CSSEGISandData/COVID-19
url <- "https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv"
dta_raw <- read_csv(url, col_types = cols()) %>%
select(-Lat, -Long)
# grep("Uni", unique(dta_raw$`Country/Region`), v = T)
selection <- c("China", "Italy", "Switzerland", "Korea, South", "France", "Germany", "Austria", "US", "United Kingdom")
dta <-
dta_raw %>%
# tidy data
rename(province = `Province/State`, country = `Country/Region`) %>%
pivot_longer(c(-province, -country), "time") %>%
mutate(time = as.Date(time, "%m/%d/%y")) %>%
# selection
filter(country %in% !! selection) %>%
# ignore provinces
group_by(country, time) %>%
summarize(value = sum(value)) %>%
ungroup() %>%
# calculate new confirmed cases
arrange(time) %>%
group_by(country) %>%
mutate(diff = value - lag(value)) %>%
ungroup() %>%
filter(!is.na(diff)) %>%
arrange(country, time)
dta %>%
filter(diff > 0) %>%
ggplot(aes(x = time, y = diff, fill = country %in% c("China", "Korea, South"))) +
geom_col(show.legend = FALSE) +
facet_wrap(vars(country), scales = "free_y") +
ggtitle("New confirmed cases", "Coronavirus disease (COVID-19), log scale")+
scale_y_continuous(trans='log10') +
theme_minimal()
Created on 2020-04-05 by the reprex package (v0.3.0)