Last active
June 20, 2020 22:01
-
-
Save mquezada/8230d80f3630aefeff896fdd133f8422 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
--- | |
title: "Muertes por comuna, mes y año en Chile 2000-2020" | |
output: html_notebook | |
--- | |
```{r} | |
library(tidyverse) | |
``` | |
# Cargar datos | |
Fuente: https://github.com/jorgeperezrojas/covid19-data/tree/master/csv/muertes_deis | |
```{r} | |
df_all <- read_csv('muertes_deis_rm.csv') | |
``` | |
# Gráficos de comunas seleccionadas | |
```{r, fig.height=3, fig.width=4} | |
df2 <- df_all %>% | |
gather('mes', 'valor', enero:diciembre) %>% | |
mutate(`año` = factor(`año`)) | |
meses <- c('enero', | |
'febrero', | |
'marzo', | |
'abril', | |
'mayo', | |
'junio', | |
'julio', | |
'agosto', | |
'septiembre', | |
'octubre', | |
'noviembre', | |
'diciembre') | |
df2$mes <- as.numeric(plyr::mapvalues(df2$mes, meses, seq(1:12))) | |
for(com in c("Recoleta", "Independencia", "Santiago", "La Pintana")) { | |
p <- ggplot(filter(df2, comuna == com), aes(x=mes, y=valor, color=`año`, group=`año`)) + | |
geom_line() + | |
scale_x_continuous(breaks = 1:12) + | |
scale_y_continuous(limits=c(0, 250)) + | |
theme(legend.position = "none") + | |
labs(x="mes", y="fallecidos", title=com, | |
subtitle="Fuente: DEIS Minsal (2000-2020)") | |
print(p) | |
} | |
``` | |
# Todas las comunas | |
```{r, fig.height=12, fig.width=16} | |
ggplot(df2, aes(x=mes, y=valor, color=`año`, group=`año`)) + | |
geom_line() + | |
facet_wrap(~ comuna) + | |
scale_x_continuous(breaks = 1:12) + | |
theme(legend.position = "none") + | |
labs(x="mes", y="fallecidos", title="Conteo de muertes totales por comuna (todas las causas) (2000-2020)", | |
subtitle="Fuente: DEIS Minsal (2018-2019 en proceso de validación, 2020 en proceso de recolección)") | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment