Skip to content
Snippets Groups Projects
Commit fab92b41 authored by Christine Choirat's avatar Christine Choirat Committed by Rok Roškar
Browse files

Added Chile plot example

parent a54084a8
No related branches found
No related tags found
No related merge requests found
......@@ -3,3 +3,7 @@ install.packages("knitr")
install.packages("tidyverse")
install.packages("data.table")
install.packages("janitor")
install.packages("rtweet")
%% Cell type:markdown id: tags:
Code slightly adapted from https://github.com/itoledor/coronavirus/blob/master/code/covid19-chile_03_plot-data.R
%% Cell type:code id: tags:
``` R
suppressPackageStartupMessages(library(tidyverse))
suppressPackageStartupMessages(library(rvest))
suppressPackageStartupMessages(library(magrittr))
suppressPackageStartupMessages(library(janitor))
suppressPackageStartupMessages(library(RColorBrewer))
suppressPackageStartupMessages(library(rtweet))
```
%% Cell type:code id: tags:
``` R
options(repr.plot.width = 12, repr.plot.height = 8)
```
%% Cell type:code id: tags:
``` R
paleta <- c(brewer.pal(n = 8, 'YlOrRd') %>% rev, brewer.pal(n = 9, 'YlGnBu') %>% tail(-1)) %>% unique()
```
%% Cell type:code id: tags:
``` R
covid19_chile <- read_rds("../../data/covid-19-chile/covid19_chile.rds")
```
%% Cell type:code id: tags:
``` R
covid19_chile_gg_1 <- covid19_chile %>% filter(region == 'Total')
covid19_chile_gg_1 <- covid19_chile_gg_1 %>% pivot_longer(starts_with('casos'), names_to = 'casos', names_prefix = 'casos_', values_to = 'Total')
covid19_chile_gg_1 <- covid19_chile_gg_1 %>% filter(casos %in% c('totales', 'recuperados'))
covid19_chile_gg_1 <- covid19_chile_gg_1 %>% mutate(casos = casos %>% str_replace('totales','confirmados'))
covid19_chile_gg_1 <- covid19_chile_gg_1 %>% ggplot(aes(x = fecha, y = Total, color = casos))
covid19_chile_gg_1 <- covid19_chile_gg_1 %+% geom_point(size = 4)
covid19_chile_gg_1 <- covid19_chile_gg_1 %+% geom_line()
covid19_chile_gg_1 <- covid19_chile_gg_1 %+% labs(title = "COVID19 Casos confirmados en Chile")
covid19_chile_gg_1 <- covid19_chile_gg_1 %+% labs(y = "Total casos confirmados")
covid19_chile_gg_1 <- covid19_chile_gg_1 %+% labs(caption = "Fuente: https://www.minsal.cl/\n @NachoToledoR")
covid19_chile_gg_1 <- covid19_chile_gg_1 %+% theme_minimal()
covid19_chile_gg_1 <- covid19_chile_gg_1 %+% theme(axis.text.x = element_text(angle = 45, hjust = 1))
covid19_chile_gg_1
```
%% Cell type:code id: tags:
``` R
covid19_chile_gg_2 <- covid19_chile %>% filter(region != 'Total')
covid19_chile_gg_2 <- covid19_chile_gg_2 %>% ggplot(aes(x = fecha, y = casos_totales, fill = region %>% fct_inorder))
covid19_chile_gg_2 <- covid19_chile_gg_2 %+% geom_col(position = "stack")
covid19_chile_gg_2 <- covid19_chile_gg_2 %+% labs(title = "COVID19 Casos confirmados en Chile", subtitle = "por Región", fill = "Región")
covid19_chile_gg_2 <- covid19_chile_gg_2 %+% labs(y = "Total casos confirmados")
covid19_chile_gg_2 <- covid19_chile_gg_2 %+% labs(caption = "Fuente: https://www.minsal.cl/\n @NachoToledoR")
covid19_chile_gg_2 <- covid19_chile_gg_2 %+% theme_minimal()
covid19_chile_gg_2 <- covid19_chile_gg_2 %+% theme_minimal()
covid19_chile_gg_2 <- covid19_chile_gg_2 %+% scale_fill_manual(values = paleta)
covid19_chile_gg_2 <- covid19_chile_gg_2 %+% theme(axis.text.x = element_text(angle = 45, hjust = 1))
covid19_chile_gg_2
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment