Last active
April 29, 2022 10:30
-
-
Save mbojan/4009c284054ee808949d12cb13f0608a to your computer and use it in GitHub Desktop.
Code behind https://twitter.com/mbojan/status/1483183854676582400. Adding an element of dynamism to https://www.nytimes.com/2022/01/06/opinion/omicron-covid-us.html.
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(dplyr) | |
library(ggplot2) | |
rawdata <- readr::read_csv( | |
"https://github.com/CSSEGISandData/COVID-19/raw/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_deaths_global.csv", | |
col_types = paste(rep(c("c", "d"), c(2, 790)), collapse="") | |
) | |
dat <- rawdata |> | |
filter(`Country/Region` == "Poland") |> | |
tidyr::pivot_longer( | |
- one_of("Province/State", "Country/Region", "Lat", "Long"), | |
names_to = "date", | |
values_to = "cumulative_covid_deaths" | |
) |> | |
transmute( | |
# Date announced so the number pretends to the day before | |
date = lubridate::mdy(date) - lubridate::ddays(1), | |
year = lubridate::year(date), | |
time = (date - lubridate::ymd(paste0(year[1], "-01-01"))) |> | |
as.integer(), | |
period_year = (date - lubridate::ymd(paste0(year, "-01-01"))) |> | |
as.integer(), | |
cumulative_covid_deaths, | |
# Differentiate to give daily deaths | |
covid_deaths = c(0, diff(cumulative_covid_deaths)) |> | |
as.integer(), | |
avg_deaths = zoo::rollmean(covid_deaths, k = 7, na.pad = TRUE) | |
) | |
pl <- dat |> | |
ggplot( | |
aes( | |
x = period_year, | |
ymin = time - avg_deaths/10, | |
ymax = time + avg_deaths/10, | |
group = year | |
) | |
) + | |
# geom_line(aes(y = time), color = "black") + | |
geom_ribbon(fill = "red", color = "red", alpha = 0.2) + | |
xlab("Days") + | |
theme_bw() + | |
theme( | |
axis.line=element_blank(), | |
# axis.text.x=element_blank(), | |
axis.text.y=element_blank(), | |
axis.ticks=element_blank(), | |
axis.title.x=element_blank(), | |
axis.title.y=element_blank(), | |
legend.position="none", | |
panel.background=element_blank(), | |
panel.border=element_blank(), | |
# panel.grid.major=element_blank(), | |
# panel.grid.minor=element_blank(), | |
plot.background=element_blank() | |
) | |
s <- seq(0, 2*pi, length = 100) | |
png("s%03d.png") | |
for(i in seq(along=s)) { | |
print(pl + coord_polar(start = s[i])) | |
} | |
dev.off() | |
system2("convert", c("-delay 2", "-loop 0", "*.png", "spiral.gif")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment