Commit bce03cc7 authored by numeroteca's avatar numeroteca

arregla errores en gráficos UCI y fallecimientos. Reordena script

parent 094aa342
# Analizar datos de Coronavirus COVID-19 en España
# Analizar datos de Coronavirus COVID-19 en España por Comunidad Autónoma
# Load data --------
# Load world data --------
# World data https://github.com/RamiKrispin/coronavirus-csv/blob/master/coronavirus_dataset.csv
world_data <- read.delim("https://raw.githubusercontent.com/RamiKrispin/coronavirus-csv/master/coronavirus_dataset.csv",sep = ",")
# Spanish data https://github.com/datadista/datasets/blob/master/COVID%2019/casos_cccaa_11032020_covid19.csv
# raw data https://raw.githubusercontent.com/datadista/datasets/master/COVID%2019/casos_cccaa_11032020_covid19.csv
# Settings
# Cambia el pie del gráfico pero conserva la fuente de los datos
caption <- "Gráfico: Numeroteca. Datos: Ministerio de Sanidad de España extraídos por Datadista.com"
# world_data <- read.delim("https://raw.githubusercontent.com/RamiKrispin/coronavirus-csv/master/coronavirus_dataset.csv",sep = ",")
# COVID19 in Spain -----------
# Data by Ministerio de Sanidad de España (published in PDF format https://www.mscbs.gob.es/profesionales/saludPublica/ccayes/alertasActual/nCov-China/situacionActual.htm)
# extracted by Datadista and published in this repository https://github.com/datadista/datasets/tree/master/COVID%2019
# Spanish data https://github.com/datadista/datasets/tree/master/COVID%2019
data_cases_original <- read.delim("https://github.com/datadista/datasets/raw/master/COVID%2019/12-03-2020/casos_cccaa_12032020_covid19.csv",sep = ",")
data_death_original <- read.delim("https://raw.githubusercontent.com/datadista/datasets/master/COVID%2019/12-03-2020/fallecidos_cccaa_12032020_covid19.csv",sep = ",")
data_uci_original <- read.delim("https://raw.githubusercontent.com/datadista/datasets/master/COVID%2019/12-03-2020/uci_cccaa_12032020_covid19.csv",sep = ",")
# Cases ------------
spanish_data <- read.delim("https://github.com/datadista/datasets/blob/master/COVID%2019/11-03-2020/casos_cccaa_11032020_covid19.csv",sep = ",")
# Process data ------
# Change to long format
data <- melt(data_original, id.vars = c("CCAA", "cod_ine"))
data$date <- as.Date(substr(data$variable,2,12),"%d.%m.%Y")
data <- select(data,-variable)
# Casos registrados
data_cases <- melt(data_cases_original, id.vars = c("CCAA", "cod_ine"))
data_cases$date <- as.Date(substr(data_cases$variable,2,12),"%d.%m.%Y")
data_cases <- select(data_cases,-variable)
# Personas UCI registradas
data_uci <- melt(data_uci_original, id.vars = c("CCAA"))
data_uci$date <- as.Date(substr(data_uci$variable,2,12),"%d.%m.%Y")
data_uci <- select(data_uci,-variable)
# Fallecimientos registrados
data_death <- melt(data_death_original, id.vars = c("CCAA"))
data_death$date <- as.Date(substr(data_death$variable,2,12),"%d.%m.%Y")
data_death <- select(data_death,-variable)
# Settings -------
# Cambia el pie del gráfico pero conserva la fuente de los datos
caption <- "Gráfico: Numeroteca. Datos: Ministerio de Sanidad de España extraídos por Datadista.com"
# Cases ------------
# Escala lineal
data %>% filter( CCAA != "Total") %>%
png(filename=paste("img/covid19_casos-registrados-por-comunidad-autonoma-lineal.png", sep = ""),width = 1000,height = 700)
data_cases %>% filter( CCAA != "Total") %>%
ggplot() +
geom_step(aes(date,value,group=CCAA) ) +
facet_wrap( ~CCAA) +
......@@ -44,9 +57,11 @@ ggplot() +
y = "casos",
x = "fecha",
caption = caption)
dev.off()
# Escala logarítmica
data %>% filter( CCAA != "Total") %>%
png(filename=paste("img/covid19_casos-registrados-por-comunidad-autonoma-log.png", sep = ""),width = 1000,height = 700)
data_cases %>% filter( CCAA != "Total") %>%
ggplot() +
geom_step(aes(date,value,group=CCAA) ) +
scale_y_log10( ) +
......@@ -62,24 +77,18 @@ ggplot() +
axis.ticks.x = element_line(color = "#000000")
# legend.position = "bottom"
) +
labs(title = "Número de casos de COVID19 registrados en España",
labs(title = "Número de casos de COVID19 registrados en España",
subtitle = "Por Comunidad Autónoma (escala logarítmica)",
y = "casos",
x = "fecha",
caption = caption)
dev.off()
# UCI (intensive care) -------------------
uci_spanish_data <- read.delim("https://raw.githubusercontent.com/datadista/datasets/master/COVID%2019/11-03-2020/uci_cccaa_11032020_covid19.csv",sep = ",")
# Change to long format
data_uci <- melt(data_original, id.vars = c("CCAA", "cod_ine"))
data_uci$date <- as.Date(substr(data_uci$variable,2,12),"%d.%m.%Y")
data_uci <- select(data_uci,-variable)
# Escala lineal
data_death %>% filter( CCAA != "Total") %>%
png(filename=paste("img/covid19_casos-registrados-UCI-por-comunidad-autonoma-lineal.png", sep = ""),width = 1000,height = 700)
data_uci %>% filter( CCAA != "Total") %>%
ggplot() +
geom_step(aes(date,value,group=CCAA) ) +
facet_wrap( ~CCAA) +
......@@ -99,9 +108,11 @@ data_death %>% filter( CCAA != "Total") %>%
y = "personas en UCI",
x = "fecha",
caption = caption)
dev.off()
# Escala logarítmica
data_death %>% filter( CCAA != "Total") %>%
png(filename=paste("img/covid19_casos-registrados-UCI-por-comunidad-autonoma-log.png", sep = ""),width = 1000,height = 700)
data_uci %>% filter( CCAA != "Total") %>%
ggplot() +
geom_step(aes(date,value,group=CCAA) ) +
scale_y_log10( ) +
......@@ -122,17 +133,12 @@ data_death %>% filter( CCAA != "Total") %>%
y = "personas en UCI",
x = "fecha",
caption = caption)
dev.off()
# Deaths ------------
spanish_data <- read.delim("https://raw.githubusercontent.com/datadista/datasets/master/COVID%2019/11-03-2020/fallecidos_cccaa_11032020_covid19.csv",sep = ",")
# Change to long format
data_death <- melt(data_original, id.vars = c("CCAA", "cod_ine"))
data_death$date <- as.Date(substr(data_death$variable,2,12),"%d.%m.%Y")
data_death <- select(data_death,-variable)
# Escala lineal
png(filename=paste("img/covid19_fallecimientos-registrados-por-comunidad-autonoma-lineal.png", sep = ""),width = 1000,height = 700)
data_death %>% filter( CCAA != "Total") %>%
ggplot() +
geom_step(aes(date,value,group=CCAA) ) +
......@@ -148,13 +154,15 @@ data_death %>% filter( CCAA != "Total") %>%
axis.ticks.x = element_line(color = "#000000")
# legend.position = "bottom"
) +
labs(title = "Número de fallcimientos de COVID19 registrados en España",
labs(title = "Número de fallecimientos de COVID19 registrados en España",
subtitle = "Por Comunidad Autónoma (escala lineal)",
y = "fallecidos",
x = "fecha",
caption = caption)
dev.off()
# Escala logarítmica
png(filename=paste("img/covid19_fallecimientos-registrados-por-comunidad-autonoma-log.png", sep = ""),width = 1000,height = 700)
data_death %>% filter( CCAA != "Total") %>%
ggplot() +
geom_step(aes(date,value,group=CCAA) ) +
......@@ -171,8 +179,9 @@ data_death %>% filter( CCAA != "Total") %>%
axis.ticks.x = element_line(color = "#000000")
# legend.position = "bottom"
) +
labs(title = "Número de fallcimientos de COVID19registrados en España",
labs(title = "Número de fallecimientos de COVID19 registrados en España",
subtitle = "Por Comunidad Autónoma (escala logarítmica)",
y = "fallecidos",
x = "fecha",
caption = caption)
dev.off()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment