-
-
Save jmcastagnetto/391bdfc3881358c3bcc307334c696f36 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
# based on https://gist.github.com/andrewheiss/5cb3ec07be2b1bf5dea8806dfaa755e4 | |
# With minor tweaks and translation to Spanish | |
library(tidyverse) | |
library(showtext) | |
font_add_google("Fira Sans Condensed", "firasanscond") | |
font_add_google("Fira Sans Extra Condensed", "firasansextracond") | |
showtext_auto() | |
high_mean <- 12 | |
high_sd <- 4 | |
flat_mean <- 35 | |
flat_sd <- 12 | |
plt <- 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 = "Sin\nmedidas\nprotectivas", color = "white", | |
family = "firasanscond", 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 = "Con medidas\nprotectivas", color = "white", | |
family = "firasanscond", fontface = "bold") + | |
annotate(geom = "text", x = 40, y = dnorm(flat_mean, flat_mean, sd = flat_sd), | |
label = "Capacidad del Sistema de Salud", vjust = -0.5, hjust = 0, | |
family = "firasanscond", fontface = "bold") + | |
labs(x = "Tiempo desde el primer caso", | |
y = "Número\nde casos", | |
title = "¡Aplana la curva!", | |
subtitle = "Disminuye la velocidad de contagio practicando distanciamiento social", | |
caption = "Adaptado de gráficos de CDC y The Economist\nVisita flattenthecurve.com") + | |
scale_x_continuous(expand = c(0, 0)) + | |
scale_y_continuous(expand = c(0, 0)) + | |
theme_minimal(base_family = "firasansextracond") + | |
theme(panel.grid = element_blank(), | |
axis.line = element_line(color = "black"), | |
axis.text = element_blank(), | |
axis.title = element_text(family = "firasanscond", face = "bold"), | |
axis.title.y = element_text(angle = 0, vjust = 0.5), | |
plot.margin = unit(c(1, 1, 1, 0.5), "cm"), | |
plot.title = element_text(family = "firasanscond", face = "bold", size = rel(1.7)), | |
plot.subtitle = element_text(size = rel(1.2), color = "grey50"), | |
plot.caption = element_text(color = "grey50")) | |
ggsave("aplana_la_curva.pdf", | |
plt, | |
width = 6, height = 4, | |
units = "in", | |
device = cairo_pdf) | |
ggsave("aplana_la_curva.png", | |
plt, | |
width = 6, height = 4, | |
units = "in", dpi = 96) |
Author
jmcastagnetto
commented
Mar 13, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment