Last active
March 15, 2020 21:33
-
-
Save andrewheiss/5cb3ec07be2b1bf5dea8806dfaa755e4 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(tidyverse) | |
# Download Fira Sans Condensed from | |
# https://fonts.google.com/specimen/Fira+Sans+Condensed | |
high_mean <- 12 | |
high_sd <- 4 | |
flat_mean <- 35 | |
flat_sd <- 12 | |
ggplot(tibble(x = c(0, 70)), aes(x = x)) + | |
stat_function(geom = "area", fun = dnorm, n = 1000, | |
args = list(mean = high_mean, sd = high_sd), | |
fill = "#FF4136", alpha = 0.8) + | |
stat_function(geom = "area", fun = dnorm, n = 1000, | |
args = list(mean = flat_mean, sd = flat_sd), | |
fill = "#0074D9", alpha = 0.8) + | |
geom_hline(yintercept = dnorm(flat_mean, flat_mean, flat_sd), | |
linetype = "61", color = "grey75") + | |
annotate(geom = "text", x = qnorm(0.5, high_mean, high_sd), | |
y = dnorm(qnorm(0.5, high_mean, high_sd), high_mean, high_sd) / 2, | |
label = "Without\nprotective\nmeasures", color = "white", | |
family = "Fira Sans Condensed", fontface = "bold") + | |
annotate(geom = "text", x = qnorm(0.5, flat_mean, sd = flat_sd), | |
y = dnorm(qnorm(0.5, flat_mean, sd = flat_sd), flat_mean, sd = flat_sd) / 2, | |
label = "With protective\nmeasures", color = "white", | |
family = "Fira Sans Condensed", fontface = "bold") + | |
annotate(geom = "text", x = 45, y = dnorm(flat_mean, flat_mean, sd = flat_sd), | |
label = "Healthcare system capacity", vjust = -0.5, hjust = 0, | |
family = "Fira Sans Condensed", fontface = "bold") + | |
labs(x = "Time since first case", | |
y = "# of\ncases", | |
title = "Flatten the curve!", | |
subtitle = "Slow down community spread by social distancing", | |
caption = "Adapted from the CDC and The Economist\nVisit flattenthecurve.com") + | |
scale_x_continuous(expand = c(0, 0)) + | |
scale_y_continuous(expand = c(0, 0)) + | |
theme_minimal(base_family = "Fira Sans Condensed Light") + | |
theme(panel.grid = element_blank(), | |
axis.line = element_line(color = "black"), | |
axis.text = element_blank(), | |
axis.title = element_text(family = "Fira Sans Condensed", face = "bold"), | |
axis.title.y = element_text(angle = 0, vjust = 0.5), | |
plot.title = element_text(family = "Fira Sans Condensed", face = "bold", size = rel(1.7)), | |
plot.subtitle = element_text(size = rel(1.2), color = "grey50"), | |
plot.caption = element_text(color = "grey50")) | |
ggsave("flatten_the_curve.pdf", width = 6, height = 4, units = "in", device = cairo_pdf) | |
ggsave("flatten_the_curve.png", width = 6, height = 4, units = "in", type = "cairo", dpi = 300) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment