p <- data_cases_sp_provinces %>% mutate(
cases_PCR_14days = ifelse( ccaa=="Galicia" | ccaa=="Andalucía", cases_14days, cases_PCR_14days)
) %>% filter( !(is.na(ia14) & date > as.Date("2020-08-10") ) ) %>%
ggplot() +
# geom_line(aes(date, daily_cases,group=province, color=ccaa), size= 0.8 ) +
geom_line( aes(date, ia14,group=province, color=ccaa, text = paste0("<b>", province, " (", ccaa, ")</b><br>", format( round(ia14, digits = 1),
big.mark=".", decimal.mark = ","), "" ,"<br>",date )), size= 0.4
) +
# geom_point(aes(date, daily_cases, color=ccaa), size= 1 ) +
# geom_point(aes(date, cases_PCR_14days/poblacion*100000, color=ccaa), size= 0.4 ) +
# geom_text_repel(
# data = data_cases_sp_provinces %>% group_by(province) %>% filter( !is.na(cases_PCR_14days) ) %>% top_n(1, date) %>%
# filter ( cases_PCR_14days/poblacion*100000 > 15 & date > filter_date-4),
# # data=filter( data_cases_sp_provinces, date==max(data_cases_sp_provinces$date) & cases_14days/poblacion*100000 > 40),
# aes(date, cases_PCR_14days/poblacion*100000, color=ccaa,
# label=paste(format( round(cases_PCR_14days/poblacion*100000, digits = 1), nsmall=1, big.mark=".", decimal.mark = ","),province)),
# nudge_x = 2, # adjust the starting y position of the text label
# size=5,
# hjust=0,
# family = "Roboto Condensed",
# direction="y",
# segment.size = 0.1,
# segment.color="#777777"
# ) +
scale_color_manual(values = colors_prov) +
coord_cartesian(
# ylim = c( 0,max(data_cases_sp_provinces[!is.na(data_cases_sp_provinces$daily_cases),]$daily_cases) )
) +
scale_y_continuous( labels=function(x) format(round(x, digits = 0), big.mark = ".", scientific = FALSE)
) +
# scale_y_log10( labels=function(x) format(round(x, digits = 0), big.mark = ".", scientific = FALSE),
# minor_breaks = c(seq(1 , 10, 1),seq(10 , 100, 10), seq(100 , 1000, 100), seq(1000 , 10000, 1000)),
# expand = c(0,0.2) ) +
scale_x_date(date_breaks = "3 week",
date_labels = "%d/%m",
limits=c( min(data_cases_sp_provinces$date)+15, max(data_cases_sp_provinces$date)),
expand = c(0,0)
) +
theme_minimal(base_family = "Roboto Condensed",base_size = 16) +
theme(
panel.grid.minor.x = element_blank(),
panel.grid.major.x = element_blank(),
# panel.grid.minor.y = element_blank(),
axis.ticks.x = element_line(color = "#000000"),
legend.position = "right"
) +
labs(title = paste0("Incidencia acumulada 14 días COVID-19 en España ", updated),
subtitle = paste0("Casos por 100.000 habitantes en últimos 14 días por provincia ",period),
y = "Incidencia acumulada 14 días",
x = "2020-2021",
color = "CCAA",
caption = caption_provincia)
## Warning: Ignoring unknown aesthetics: text
# save interactvive
p <- ggplotly( p, tooltip = "text") %>%
layout(title = list(text = paste0('Incidencia acumulada 14 días COVID-19 en España',
'<br>',
'<sup>',
'Casos por 100.000 habitantes en últimos 14 días por provincia.',
'</sup>'))
, annotations =
list(x = 1, y = -0.11, text = "<a style='color:grey;' href='https://lab.montera34.com/covid19'>lab.montera34.com/covid19</a> | Data: <a style='color:grey;'href='https://github.com/montera34/escovid19data9'>esCOVID19data</a>",
showarrow = F, xref='paper', yref='paper',
xanchor='right', yanchor='auto', xshift=0, yshift=0,
font=list(size=15, color="grey")
),
legend = list(font = list(size = 10))
)
## Warning in prettyNum(.Internal(format(x, trim, digits, nsmall, width, 3L, :
## 'big.mark' and 'decimal.mark' are both '.', which could be confusing
p
Nota: Galicia, Andalucía, Aragón y C. Valenciana no diferencian entre PCR+ y otro tipo de positivos.
p <- data_cases_sp_provinces %>% mutate(
cases_PCR_14days = ifelse( ccaa=="Galicia" | ccaa=="Andalucía", cases_14days, cases_PCR_14days)
) %>% filter( !(is.na(ia14) & date > as.Date("2020-08-10") ) ) %>%
ggplot() +
# geom_line(aes(date, daily_cases,group=province, color=ccaa), size= 0.8 ) +
geom_line( aes(date, ia14,group=province, color=ccaa, text = paste0("<b>", province, " (", ccaa, ")</b><br>", format( round(ia14, digits = 1),
big.mark=".", decimal.mark = ","), "" ,"<br>",date )), size= 0.4
) +
# geom_point(aes(date, daily_cases, color=ccaa), size= 1 ) +
# geom_point(aes(date, cases_PCR_14days/poblacion*100000, color=ccaa), size= 0.4 ) +
# geom_text_repel(
# data = data_cases_sp_provinces %>% group_by(province) %>% filter( !is.na(cases_PCR_14days) ) %>% top_n(1, date) %>%
# filter ( cases_PCR_14days/poblacion*100000 > 15 & date > filter_date-4),
# # data=filter( data_cases_sp_provinces, date==max(data_cases_sp_provinces$date) & cases_14days/poblacion*100000 > 40),
# aes(date, cases_PCR_14days/poblacion*100000, color=ccaa,
# label=paste(format( round(cases_PCR_14days/poblacion*100000, digits = 1), nsmall=1, big.mark=".", decimal.mark = ","),province)),
# nudge_x = 2, # adjust the starting y position of the text label
# size=5,
# hjust=0,
# family = "Roboto Condensed",
# direction="y",
# segment.size = 0.1,
# segment.color="#777777"
# ) +
scale_color_manual(values = colors_prov) +
coord_cartesian(
# ylim = c( 0,max(data_cases_sp_provinces[!is.na(data_cases_sp_provinces$daily_cases),]$daily_cases) )
) +
# scale_y_continuous( labels=function(x) format(round(x, digits = 0), big.mark = ".", scientific = FALSE)
# ) +
scale_y_log10( labels=function(x) format(round(x, digits = 0), big.mark = ".", scientific = FALSE),
minor_breaks = c(seq(1 , 10, 1),seq(10 , 100, 10), seq(100 , 1000, 100), seq(1000 , 10000, 1000)),
expand = c(0,0.2) ) +
scale_x_date(date_breaks = "3 week",
date_labels = "%d/%m",
limits=c( min(data_cases_sp_provinces$date)+15, max(data_cases_sp_provinces$date)),
expand = c(0,0)
) +
theme_minimal(base_family = "Roboto Condensed",base_size = 16) +
theme(
panel.grid.minor.x = element_blank(),
panel.grid.major.x = element_blank(),
# panel.grid.minor.y = element_blank(),
axis.ticks.x = element_line(color = "#000000"),
legend.position = "right"
) +
labs(title = paste0("Incidencia acumulada 14 días COVID-19 en España ", updated),
subtitle = paste0("Casos por 100.000 habitantes en últimos 14 días por provincia. Escala logarítmica ",period),
y = "Incidencia acumulada 14 días (log)",
x = "2020-2021",
color = "CCAA",
caption = caption_provincia)
## Warning: Ignoring unknown aesthetics: text
# save interactvive
p <- ggplotly( p, tooltip = "text") %>%
layout(title = list(text = paste0('Incidencia acumulada 14 días COVID-19 en España',
'<br>',
'<sup>',
'Casos por 100.000 habitantes en últimos 14 días por provincia. Escala logarítmica ',
'</sup>'))
, annotations =
list(x = 1, y = -0.11, text = "<a style='color:grey;' href='https://lab.montera34.com/covid19'>lab.montera34.com/covid19</a> | Data: <a style='color:grey;'href='https://github.com/montera34/escovid19data9'>esCOVID19data</a>",
showarrow = F, xref='paper', yref='paper',
xanchor='right', yanchor='auto', xshift=0, yshift=0,
font=list(size=15, color="grey")
),
legend = list(font = list(size = 10))
)
## Warning in self$trans$transform(x): Se han producido NaNs
## Warning: Transformation introduced infinite values in continuous y-axis
## Warning in prettyNum(.Internal(format(x, trim, digits, nsmall, width, 3L, :
## 'big.mark' and 'decimal.mark' are both '.', which could be confusing
p
Nota: Galicia, Andalucía, Aragón y C. Valenciana no diferencian entre PCR+ y otro tipo de positivos.
interactive_dp <- data_cases_sp_provinces %>%
mutate(
daily_cases_PCR_avg7 = ifelse( date > as.Date("2020-10-02") & is.na(daily_cases_PCR_avg7), daily_cases_avg7, daily_cases_PCR_avg7 )
) %>% filter( !(is.na(daily_cases_PCR_avg7) & date > as.Date("2020-08-10") ) ) %>%
ggplot() +
geom_line(aes(date, daily_cases_PCR_avg7, group = province, color=ccaa,
text = paste0("<b>", province, " (", ccaa, ")</b><br>", format( round(daily_cases_PCR_avg7, digits = 1),
big.mark=".", decimal.mark = ","), " media casos diaria (ventana 7 días)" ,"<br>",date )),
size= 0.4, se = FALSE, span = 0.6 ) +
# geom_point(aes(date, daily_cases_PCR, color=ccaa,
# text = paste0("<b>", province, " (", ccaa, ")</b><br>", format( round(daily_cases_PCR, digits = 1),
# big.mark=".", decimal.mark = ","), " casos el día " ,"<br>",date )),
# size= 0.3
# ) +
scale_color_manual(values = colors_prov) +
coord_cartesian(
# ylim = c(1, max(data_cases_sp_provinces[!is.na(data_cases_sp_provinces$daily_cases_PCR_avg7) & (date > data_cases_sp_provinces$filter_date - 50),]$daily_cases_PCR_avg7) )
ylim = c(0, 5200 )
) +
scale_y_continuous( labels=function(x) format(round(x, digits = 0), big.mark = ".", scientific = FALSE),
# minor_breaks = c(seq(1 , 10, 1),seq(10 , 100, 10), seq(100 , 1000, 100), seq(1000 , 10000, 1000)),
expand = c(0,0.2) ) +
scale_x_date(date_breaks = "3 week",
date_labels = "%d/%m",
limits=c( min(data_cases_sp_provinces$date)+13, max(data_cases_sp_provinces$date + 1)),
expand = c(0,0)
) +
theme_minimal(base_family = "Roboto Condensed",base_size = 16) +
theme(
panel.grid.minor.x = element_blank(),
panel.grid.major.x = element_blank(),
# panel.grid.minor.y = element_blank(),
axis.ticks.x = element_line(color = "#000000"),
legend.position = c(0.3,0.9)
) +
labs(title = paste0("Media de casos por día (media 7 días) por COVID-19. España ", updated ),
subtitle = paste0("Por provincia. Escala logarítmica ",period),
y = "casos por día (media 7 días)",
x = "2020-2021",
caption = caption_provincia)
## Warning: Ignoring unknown parameters: se, span
## Warning: Ignoring unknown aesthetics: text
# save interactvive
interactive_dp_p <- ggplotly(interactive_dp, tooltip = "text") %>%
layout(title = list(text = paste0('Media de casos por día (ventana 7 días) por COVID-19.',
'<br>',
'<sup>',
' Últimos 50 días. Por provincia. Escala lineal',
'</sup>')),
legend = list(font = list(size = 10))
, annotations =
list(x = 1, y = -0.11, text = "<a style='color:grey;' href='https://lab.montera34.com/covid19'>lab.montera34.com/covid19</a> | Data: <a style='color:grey;'href='https://github.com/montera34/escovid19data9'>esCOVID19data</a>",
showarrow = F, xref='paper', yref='paper',
xanchor='right', yanchor='auto', xshift=0, yshift=0,
font=list(size=15, color="grey")
)
)
## Warning in prettyNum(.Internal(format(x, trim, digits, nsmall, width, 3L, :
## 'big.mark' and 'decimal.mark' are both '.', which could be confusing
interactive_dp_p
Se usan casos PCR+, menos las CCAA que empezaron a usar test de antígenos a partir de octubre de 2020.
# interactive_dp <- data_cases_sp_provinces %>%
# filter ( date > filter_date - 50 ) %>%
# mutate(
# daily_cases_PCR_avg7 = ifelse( date > as.Date("2020-10-02") & is.na(daily_cases_PCR_avg7), daily_cases_avg7, daily_cases_PCR_avg7 )
# ) %>% filter( !(is.na(daily_cases_PCR_avg7) & date > as.Date("2020-08-10") ) ) %>%
# ggplot() +
# geom_line(aes(date, daily_cases_PCR_avg7, group = province, color=ccaa,
# text = paste0("<b>", province, " (", ccaa, ")</b><br>", format( round(daily_cases_PCR_avg7, digits = 1),
# big.mark=".", decimal.mark = ","), " media casos diaria (ventana 7 días)" ,"<br>",date )),
# size= 0.4, se = FALSE, span = 0.6 ) +
# # geom_point(aes(date, daily_cases_PCR, color=ccaa,
# # text = paste0("<b>", province, " (", ccaa, ")</b><br>", format( round(daily_cases_PCR, digits = 1),
# # big.mark=".", decimal.mark = ","), " casos el día " ,"<br>",date )),
# # size= 0.3
# # ) +
# scale_color_manual(values = colors_prov) +
# coord_cartesian(
# # ylim = c(1, max(data_cases_sp_provinces[!is.na(data_cases_sp_provinces$daily_cases_PCR_avg7) & (date > data_cases_sp_provinces$filter_date - 50),]$daily_cases_PCR_avg7) )
# ylim = c(0, 5200 )
# ) +
# scale_y_continuous( labels=function(x) format(round(x, digits = 0), big.mark = ".", scientific = FALSE),
# # minor_breaks = c(seq(1 , 10, 1),seq(10 , 100, 10), seq(100 , 1000, 100), seq(1000 , 10000, 1000)),
# expand = c(0,0.2) ) +
# scale_x_date(date_breaks = "1 week",
# date_labels = "%d/%m",
# limits=c( filter_date - 50, max(data_cases_sp_provinces$date + 1)),
# expand = c(0,0)
# ) +
# theme_minimal(base_family = "Roboto Condensed",base_size = 16) +
# theme(
# panel.grid.minor.x = element_blank(),
# panel.grid.major.x = element_blank(),
# # panel.grid.minor.y = element_blank(),
# axis.ticks.x = element_line(color = "#000000"),
# legend.position = c(0.3,0.9)
# ) +
# labs(title = paste0("Media de casos por día (media 7 días) por COVID-19. España ", updated ),
# subtitle = paste0("Por provincia. Escala logarítmica ",period),
# y = "casos por día (media 7 días)",
# x = "2020-2021",
# caption = caption_provincia)
#
#
# # save interactvive
# interactive_dp_p <- ggplotly(interactive_dp, tooltip = "text") %>%
# layout(title = list(text = paste0('Media de casos por día (ventana 7 días) por COVID-19.',
# '<br>',
# '<sup>',
# ' Últimos 50 días. Por provincia. Escala lineal',
# '</sup>')),
# legend = list(font = list(size = 10))
# , annotations =
# list(x = 1, y = -0.11, text = "<a style='color:grey;' href='https://lab.montera34.com/covid19'>lab.montera34.com/covid19</a> | Data: <a style='color:grey;'href='https://github.com/montera34/escovid19data9'>esCOVID19data</a>",
# showarrow = F, xref='paper', yref='paper',
# xanchor='right', yanchor='auto', xshift=0, yshift=0,
# font=list(size=15, color="grey")
# )
# )
#
# interactive_dp_p
Se usan casos PCR+, menos las CCAA que empezaron a usar test de antígenos a partir de octubre de 2020.
interactive_dp <- data_cases_sp_provinces %>% mutate(
daily_cases_PCR_avg7 = ifelse( date > as.Date("2020-10-02") & is.na(daily_cases_PCR_avg7), daily_cases_avg7, daily_cases_PCR_avg7 )
) %>% filter( !(is.na(daily_cases_PCR_avg7) & date > as.Date("2020-08-10") ) ) %>%
ggplot() +
geom_line(aes(date, daily_cases_PCR_avg7, group = province, color=ccaa,
text = paste0("<b>", province, " (", ccaa, ")</b><br>", format( round(daily_cases_PCR_avg7, digits = 1),
big.mark=".", decimal.mark = ","), " media casos diaria (ventana 7 días)" ,"<br>",date )),
size= 0.4, se = FALSE, span = 0.6 ) +
# geom_point(aes(date, daily_cases_PCR, color=ccaa,
# text = paste0("<b>", province, " (", ccaa, ")</b><br>", format( round(daily_cases_PCR, digits = 1),
# big.mark=".", decimal.mark = ","), " casos el día " ,"<br>",date )),
# size= 0.3
# ) +
scale_color_manual(values = colors_prov) +
coord_cartesian(
ylim = c(1,3500)
) +
scale_y_log10( labels=function(x) format(round(x, digits = 0), big.mark = ".", scientific = FALSE),
minor_breaks = c(seq(1 , 10, 1),seq(10 , 100, 10), seq(100 , 1000, 100), seq(1000 , 10000, 1000)),
expand = c(0,0.2) ) +
scale_x_date(date_breaks = "3 week",
date_labels = "%d/%m",
limits=c( min(data_cases_sp_provinces$date)+13, max(data_cases_sp_provinces$date + 1)),
expand = c(0,0)
) +
theme_minimal(base_family = "Roboto Condensed",base_size = 16) +
theme(
panel.grid.minor.x = element_blank(),
panel.grid.major.x = element_blank(),
# panel.grid.minor.y = element_blank(),
axis.ticks.x = element_line(color = "#000000"),
legend.position = c(0.3,0.9)
) +
labs(title = paste0("Media de casos por día (media 7 días) por COVID-19. España ", updated ),
subtitle = paste0("Por provincia. Escala logarítmica ",period),
y = "casos por día (media 7 días)",
x = "2020-2021",
caption = caption_provincia)
## Warning: Ignoring unknown parameters: se, span
## Warning: Ignoring unknown aesthetics: text
# save interactvive
interactive_dp_p <- ggplotly(interactive_dp, tooltip = "text") %>%
layout(title = list(text = paste0('Media de casos por día (ventana 7 días) por COVID-19',
'<br>',
'<sup>',
'Por provincia. Escala logarítmica.',
'</sup>'))
, annotations =
list(x = 1, y = -0.11, text = "<a style='color:grey;' href='https://lab.montera34.com/covid19'>lab.montera34.com/covid19</a> | Data: <a style='color:grey;'href='https://github.com/montera34/escovid19data9'>esCOVID19data</a>",
showarrow = F, xref='paper', yref='paper',
xanchor='right', yanchor='auto', xshift=0, yshift=0,
font=list(size=15, color="grey")
),
legend = list(font = list(size = 10))
)
## Warning in self$trans$transform(x): Se han producido NaNs
## Warning: Transformation introduced infinite values in continuous y-axis
## Warning in prettyNum(.Internal(format(x, trim, digits, nsmall, width, 3L, :
## 'big.mark' and 'decimal.mark' are both '.', which could be confusing
interactive_dp_p
Se usan casos PCR+, menos las CCAA que empezaron a usar test de antígenos a partir de octubre de 2020.
# p2 <- data_cases_sp_provinces %>% mutate(
# cases_PCR_14days = ifelse( ccaa=="Galicia" | ccaa=="Andalucía", cases_14days, cases_PCR_14days)
# ) %>% mutate(
# cases_PCR_14days = ifelse( date > as.Date("2020-10-02") & is.na(cases_PCR_14days), cases_14days, cases_PCR_14days )
# ) %>% filter( !(is.na(daily_cases_PCR_avg7) & date > as.Date("2020-08-10") ) ) %>%
# ggplot() +
# geom_line(aes(date, cases_PCR_14days,group=province, color=ccaa, text = paste0("<b>", province, " (", ccaa, ")</b><br>", format( round(cases_PCR_14days, digits = 1),
# big.mark=".", decimal.mark = ","), " casos en 14 días" ,"<br>",date )), size= 0.4 ) +
# # geom_point(aes(date, cases_PCR_14days, color=ccaa), size= 1 ) +
# # geom_text_repel( data = data_cases_sp_provinces %>% group_by(province) %>% filter( !is.na(cases_PCR_14days) ) %>% top_n(1, date) %>%
# # filter ( cases_PCR_14days > 100 & date > filter_date-7),
# # aes(date, cases_PCR_14days, color=ccaa, label=paste(format(cases_PCR_14days, nsmall=1, big.mark=".", decimal.mark = ","),province)),
# # nudge_x = 4, # adjust the starting y position of the text label
# # size=5,
# # hjust=0,
# # family = "Roboto Condensed",
# # direction="y",
# # segment.size = 0.1,
# # segment.color="#777777"
# # ) +
# scale_color_manual(values = colors_prov) +
# coord_cartesian(
# ) +
# scale_y_log10( labels=function(x) format(round(x, digits = 0), big.mark = ".", scientific = FALSE)
# ) +
# scale_x_date(date_breaks = "3 week",
# date_labels = "%d/%m",
# limits=c( min(data_cases_sp_provinces$date)+15, max(data_cases_sp_provinces$date)),
# expand = c(0,0)
# ) +
# theme_minimal(base_family = "Roboto Condensed",base_size = 16) +
# theme(
# panel.grid.minor.x = element_blank(),
# panel.grid.major.x = element_blank(),
# # panel.grid.minor.y = element_blank(),
# axis.ticks.x = element_line(color = "#000000")
# # legend.position = "none"
# ) +
# labs(title = paste0("Casos últimos 14 días por COVID-19 en España ", updated),
# subtitle = paste0("Por provincia ",period),
# y = "casos",
# x = "2020-2021",
# caption = caption_provincia)
#
# # save interactvive
# p2 <- ggplotly(p2, tooltip = "text") %>%
# layout(title = list(text = paste0('Casos en los últimos 14 días por COVID-19 en España',
# '<br>',
# '<sup>',
# 'Por provincia',
# '</sup>'))
# , annotations =
# list(x = 1, y = -0.11, text = "<a style='color:grey;' href='https://lab.montera34.com/covid19'>lab.montera34.com/covid19</a> | Data: <a style='color:grey;'href='https://github.com/montera34/escovid19data9'>esCOVID19data</a>",
# showarrow = F, xref='paper', yref='paper',
# xanchor='right', yanchor='auto', xshift=0, yshift=0,
# font=list(size=15, color="grey")
# ),
# legend = list(font = list(size = 10))
# )
#
# p2
# Remove not prevalent hospitalized data for Murcia and Navarra early days
data_cases_sp_provinces <- readRDS(file = "../data/output/spain/covid19-provincias-spain_consolidated.rds")
data_cases_sp_provinces <- data_cases_sp_provinces %>% filter( (date > as.Date("2020-02-25") ) & ( date < filter_date ) )
# Remove not prevalent hospitalized data early days ---
data_cases_sp_provinces <- data_cases_sp_provinces %>% mutate(
hospitalized = ifelse( (province== "Murcia") & ( date < as.Date("2020-07-16" ) ), NA, hospitalized ),
intensive_care = ifelse( (province== "Murcia") & ( date < as.Date("2020-07-16" ) ), NA, intensive_care ),
hospitalized = ifelse( (province== "Navarra") & ( date < as.Date("2020-07-16" ) ), NA, hospitalized ),
intensive_care = ifelse( (province== "Navarra") & ( date < as.Date("2020-07-16" ) ), NA, intensive_care ),
hospitalized = ifelse( (province== "Ceuta") & ( date < as.Date("2020-07-16" ) ), NA, hospitalized ),
intensive_care = ifelse( (province== "Ceuta") & ( date < as.Date("2020-07-16" ) ), NA, intensive_care ),
hospitalized = ifelse( (province== "Melilla") & ( date < as.Date("2020-07-16" ) ), NA, hospitalized ),
intensive_care = ifelse( (province== "Melilla") & ( date < as.Date("2020-07-16" ) ), NA, intensive_care ),
hospitalized = ifelse( (province== "Rioja, La") & ( date < as.Date("2020-07-16" ) ), NA, hospitalized ),
intensive_care = ifelse( (province== "Rioja, La") & ( date < as.Date("2020-07-16" ) ), NA, intensive_care ),
hospitalized = ifelse( (province== "Rioja, La") & ( date < as.Date("2020-07-16" ) ), NA, hospitalized ),
hospitalized_per_100000 = ifelse( (province== "Murcia") & ( date < as.Date("2020-07-16" ) ), NA, hospitalized_per_100000 ),
hospitalized_per_100000 = ifelse( (province== "Navarra") & ( date < as.Date("2020-07-16" ) ), NA, hospitalized_per_100000 ),
hospitalized_per_100000 = ifelse( (province== "Ceuta") & ( date < as.Date("2020-07-16" ) ), NA, hospitalized_per_100000 ),
hospitalized_per_100000 = ifelse( (province== "Melilla") & ( date < as.Date("2020-07-16" ) ), NA, hospitalized_per_100000 ),
hospitalized_per_100000 = ifelse( (province== "Rioja, La") & ( date < as.Date("2020-07-16" ) ), NA, hospitalized_per_100000 )
)
# Solamente deja las ccaa prevalentes
noprevalentes <- c("")
data_cases_sp_provincesX <- data_cases_sp_provinces %>% filter( ! ccaa %in% noprevalentes )
data_cases_sp_provincesX_sm <- data_cases_sp_provinces_sm %>% filter( ! ccaa %in% noprevalentes )
# creates extended color palette https://www.r-bloggers.com/how-to-expand-color-palette-with-ggplot-and-rcolorbrewer/
colourCount <- length(unique(data_cases_sp_provincesX$ccaa))
getPalette <- colorRampPalette(brewer.pal(9, "Set1"))
colors_provX <- getPalette(colourCount )
# Change yellow to blue
colors_provX[1] <- "#a60000"
colors_provX[12] <- "#84d3e7"
p2 <- data_cases_sp_provincesX %>% filter( !(is.na(hospitalized) & date > as.Date("2020-08-10") ) ) %>%
ggplot() +
geom_line(aes(date, hospitalized,group=province, color=ccaa, text = paste0("<b>", province, " (", ccaa, ")</b><br>", format( round(hospitalized, digits = 1),
big.mark=".", decimal.mark = ","), " hospitalizados" ,"<br>",date )), size= 0.4) +
# geom_line(aes(date, intensive_care,group=province, text = paste0("<b>", province, " (", ccaa, ")</b><br>", format( round(intensive_care, digits = 1),
# big.mark=".", decimal.mark = ","), " UCI" ,"<br>",date )), size= 0.7, color = "grey") +
scale_color_manual(values = colors_provX) +
scale_y_continuous( labels=function(x) format(round(x, digits = 0), big.mark = ".", scientific = FALSE),
# minor_breaks = c(seq(1 , 10, 1),seq(10 , 100, 10), seq(100 , 1000, 100), seq(1000 , 10000, 1000)),
expand = c(0,0.1) ) +
scale_x_date(date_breaks = "3 week",
date_labels = "%d/%m",
limits=c( min(data_cases_sp_provincesX$date)+7, max(data_cases_sp_provincesX$date )),
expand = c(0,0)
) +
theme_minimal(base_family = "Roboto Condensed",base_size = 16) +
theme(
panel.grid.minor.x = element_blank(),
panel.grid.major.x = element_blank(),
# panel.grid.minor.y = element_blank(),
axis.ticks.x = element_line(color = "#000000"),
legend.position = c(0.07,0.7)
) +
labs(title = paste0("Hospitalizados prevalentes por COVID-19 en España ", updated ),
subtitle = paste0("Por provincia. ",period),
y = "hospitalizados",
x = "2020-2021",
caption = caption_provincia)
## Warning: Ignoring unknown aesthetics: text
# save interactvive
p2 <- ggplotly(p2, tooltip = "text") %>%
layout(title = list(text = paste0('Hospitalizados prevalentes por COVID-19 en España',
'<br>',
'<sup>',
'Por provincia ',
'</sup>'))
, annotations =
list(x = 1, y = -0.11, text = "<a style='color:grey;' href='https://lab.montera34.com/covid19'>lab.montera34.com/covid19</a> | Data: <a style='color:grey;'href='https://github.com/montera34/escovid19data9'>esCOVID19data</a>",
showarrow = F, xref='paper', yref='paper',
xanchor='right', yanchor='auto', xshift=0, yshift=0,
font=list(size=15, color="grey")
),
legend = list(font = list(size = 10))
)
## Warning in prettyNum(.Internal(format(x, trim, digits, nsmall, width, 3L, :
## 'big.mark' and 'decimal.mark' are both '.', which could be confusing
p2
# p2 <- data_cases_sp_provincesX %>% filter( !(is.na(hospitalized) & date > as.Date("2020-08-10") ) ) %>%
# ggplot() +
# geom_line(aes(date, hospitalized,group=province, color=ccaa, text = paste0("<b>", province, " (", ccaa, ")</b><br>", format( round(hospitalized, digits = 1),
# big.mark=".", decimal.mark = ","), " hospitalizados" ,"<br>",date )), size= 0.4) +
# # geom_line(aes(date, intensive_care,group=province, text = paste0("<b>", province, " (", ccaa, ")</b><br>", format( round(intensive_care, digits = 1),
# # big.mark=".", decimal.mark = ","), " UCI" ,"<br>",date )), size= 0.7, color = "grey") +
# scale_color_manual(values = colors_provX) +
# scale_y_log10( labels=function(x) format(round(x, digits = 0), big.mark = ".", scientific = FALSE),
# minor_breaks = c(seq(1 , 10, 1),seq(10 , 100, 10), seq(100 , 1000, 100), seq(1000 , 10000, 1000)),
# expand = c(0,0.1) ) +
# scale_x_date(date_breaks = "3 week",
# date_labels = "%d/%m",
# limits=c( min(data_cases_sp_provincesX$date)+7, max(data_cases_sp_provincesX$date )),
# expand = c(0,0)
# ) +
# theme_minimal(base_family = "Roboto Condensed",base_size = 16) +
# theme(
# panel.grid.minor.x = element_blank(),
# panel.grid.major.x = element_blank(),
# # panel.grid.minor.y = element_blank(),
# axis.ticks.x = element_line(color = "#000000"),
# legend.position = c(0.07,0.7)
# ) +
# labs(title = paste0("Hospitalizados prevalentes por COVID-19 en España ", updated ),
# subtitle = paste0("Por provincia (escala logarítmica). ",period),
# y = "hospitalizados",
# x = "2020-2021",
# caption = caption_provincia)
#
#
# # save interactvive
# p2 <- ggplotly(p2, tooltip = "text") %>%
# layout(title = list(text = paste0('Hospitalizados prevalentes por COVID-19 en España',
# '<br>',
# '<sup>',
# 'Por provincia (escala logarítmica)',
# '</sup>'))
# , annotations =
# list(x = 1, y = -0.11, text = "<a style='color:grey;' href='https://lab.montera34.com/covid19'>lab.montera34.com/covid19</a> | Data: <a style='color:grey;'href='https://github.com/montera34/escovid19data9'>esCOVID19data</a>",
# showarrow = F, xref='paper', yref='paper',
# xanchor='right', yanchor='auto', xshift=0, yshift=0,
# font=list(size=15, color="grey")
# ),
# legend = list(font = list(size = 10))
# )
#
# p2
p2 <- data_cases_sp_provincesX %>% filter( !(is.na(hospitalized) & date > as.Date("2020-08-10") ) ) %>%
ggplot() +
geom_line(aes(date, hospitalized/poblacion*100000,group=province, color=ccaa, text = paste0("<b>", province, " (", ccaa, ")</b><br>", format( round(hospitalized/poblacion*100000, digits = 1),
big.mark=".", decimal.mark = ","), " hospitalizados" ,"<br>",date )), size= 0.4) +
# geom_line(aes(date, intensive_care,group=province, text = paste0("<b>", province, " (", ccaa, ")</b><br>", format( round(intensive_care, digits = 1),
# big.mark=".", decimal.mark = ","), " UCI" ,"<br>",date )), size= 0.7, color = "grey") +
scale_color_manual(values = colors_provX) +
scale_y_continuous( labels=function(x) format(round(x, digits = 0), big.mark = ".", scientific = FALSE),
# minor_breaks = c(seq(1 , 10, 1),seq(10 , 100, 10), seq(100 , 1000, 100), seq(1000 , 10000, 1000)),
expand = c(0,0.1) ) +
scale_x_date(date_breaks = "3 week",
date_labels = "%d/%m",
limits=c( min(data_cases_sp_provincesX$date)+7, max(data_cases_sp_provincesX$date )),
expand = c(0,0)
) +
theme_minimal(base_family = "Roboto Condensed",base_size = 16) +
theme(
panel.grid.minor.x = element_blank(),
panel.grid.major.x = element_blank(),
# panel.grid.minor.y = element_blank(),
axis.ticks.x = element_line(color = "#000000"),
legend.position = c(0.07,0.7)
) +
labs(title = paste0("Hospitalizados prevalentes por COVID-19 en España por 100.000 habitantes ", updated ),
subtitle = paste0("Por provincia. ",period),
y = "hospitalizados",
x = "2020-2021",
caption = caption_provincia)
## Warning: Ignoring unknown aesthetics: text
# save interactvive
p2 <- ggplotly(p2, tooltip = "text") %>%
layout(title = list(text = paste0('Hospitalizados prevalentes por COVID-19 en España por 100.000 habitantes',
'<br>',
'<sup>',
'Por provincia ',
'</sup>'))
, annotations =
list(x = 1, y = -0.11, text = "<a style='color:grey;' href='https://lab.montera34.com/covid19'>lab.montera34.com/covid19</a> | Data: <a style='color:grey;'href='https://github.com/montera34/escovid19data9'>esCOVID19data</a>",
showarrow = F, xref='paper', yref='paper',
xanchor='right', yanchor='auto', xshift=0, yshift=0,
font=list(size=15, color="grey")
),
legend = list(font = list(size = 10))
)
## Warning in prettyNum(.Internal(format(x, trim, digits, nsmall, width, 3L, :
## 'big.mark' and 'decimal.mark' are both '.', which could be confusing
p2
# p2 <- data_cases_sp_provincesX %>% filter( !(is.na(hospitalized) & date > as.Date("2020-08-10") ) ) %>%
# ggplot() +
# geom_line(aes(date, hospitalized_new,group=province, color=ccaa, text = paste0("<b>", province, " (", ccaa, ")</b><br>", format( round( hospitalized_new, digits = 1),
# big.mark=".", decimal.mark = ","), " ingresos nuevos en planta" ,"<br>",date )), size= 0.4) +
# # geom_line(aes(date, intensive_care,group=province, text = paste0("<b>", province, " (", ccaa, ")</b><br>", format( round(intensive_care, digits = 1),
# # big.mark=".", decimal.mark = ","), " UCI" ,"<br>",date )), size= 0.7, color = "grey") +
# scale_color_manual(values = colors_provX) +
# scale_y_log10( labels=function(x) format(round(x, digits = 0), big.mark = ".", scientific = FALSE),
# minor_breaks = c(seq(1 , 10, 1),seq(10 , 100, 10), seq(100 , 1000, 100), seq(1000 , 10000, 1000)),
# expand = c(0,0.1) ) +
# scale_x_date(date_breaks = "3 week",
# date_labels = "%d/%m",
# limits=c( min(data_cases_sp_provincesX$date)+7, max(data_cases_sp_provincesX$date )),
# expand = c(0,0)
# ) +
# theme_minimal(base_family = "Roboto Condensed",base_size = 16) +
# theme(
# panel.grid.minor.x = element_blank(),
# panel.grid.major.x = element_blank(),
# # panel.grid.minor.y = element_blank(),
# axis.ticks.x = element_line(color = "#000000"),
# legend.position = c(0.07,0.7)
# ) +
# labs(title = paste0("Hospitalizados prevalentes por COVID-19 en España ", updated ),
# subtitle = paste0("Por provincia (escala logarítmica). ",period),
# y = "hospitalizados",
# x = "2020-2021",
# caption = caption_provincia)
#
#
# # save interactvive
# p2 <- ggplotly(p2, tooltip = "text") %>%
# layout(title = list(text = paste0('Ingresados nuevos en hospital por COVID-19 en España',
# '<br>',
# '<sup>',
# 'Por provincia (escala logarítmica)',
# '</sup>'))
# , annotations =
# list(x = 1, y = -0.11, text = "<a style='color:grey;' href='https://lab.montera34.com/covid19'>lab.montera34.com/covid19</a> | Data: <a style='color:grey;'href='https://github.com/montera34/escovid19data9'>esCOVID19data</a>",
# showarrow = F, xref='paper', yref='paper',
# xanchor='right', yanchor='auto', xshift=0, yshift=0,
# font=list(size=15, color="grey")
# ),
# legend = list(font = list(size = 10))
# )
#
# p2
p2 <- data_cases_sp_provincesX %>% filter( !(is.na(intensive_care) & date > as.Date("2020-08-10") ) ) %>%
ggplot() +
geom_line(aes(date, intensive_care,group=province, color=ccaa, text = paste0("<b>", province, " (", ccaa, ")</b><br>", format( round(intensive_care, digits = 1),
big.mark=".", decimal.mark = ","), " UCI" ,"<br>",date )), size= 0.4) +
scale_color_manual(values = colors_provX) +
scale_y_continuous( labels=function(x) format(round(x, digits = 0), big.mark = ".", scientific = FALSE),
# minor_breaks = c(seq(1 , 10, 1),seq(10 , 100, 10), seq(100 , 1000, 100), seq(1000 , 10000, 1000)),
expand = c(0,0.1) ) +
scale_x_date(date_breaks = "3 week",
date_labels = "%d/%m",
limits=c( min(data_cases_sp_provincesX$date)+7, max(data_cases_sp_provincesX$date )),
expand = c(0,0)
) +
theme_minimal(base_family = "Roboto Condensed",base_size = 16) +
theme(
panel.grid.minor.x = element_blank(),
panel.grid.major.x = element_blank(),
# panel.grid.minor.y = element_blank(),
axis.ticks.x = element_line(color = "#000000"),
legend.position = c(0.07,0.7)
) +
labs(title = paste0("UCI (hospitalizados) por COVID-19 en España ", updated ),
subtitle = paste0("Por provincia. ",period),
y = "hospitalizados",
x = "2020-2021",
caption = caption_provincia)
## Warning: Ignoring unknown aesthetics: text
# save interactvive
p2 <- ggplotly(p2, tooltip = "text") %>%
layout(title = list(text = paste0('UCI (hospitalizados) por COVID-19 en España',
'<br>',
'<sup>',
'Por provincia',
'</sup>'))
, annotations =
list(x = 1, y = -0.11, text = "<a style='color:grey;' href='https://lab.montera34.com/covid19'>lab.montera34.com/covid19</a> | Data: <a style='color:grey;'href='https://github.com/montera34/escovid19data9'>esCOVID19data</a>",
showarrow = F, xref='paper', yref='paper',
xanchor='right', yanchor='auto', xshift=0, yshift=0,
font=list(size=15, color="grey")
),
legend = list(font = list(size = 10))
)
## Warning in prettyNum(.Internal(format(x, trim, digits, nsmall, width, 3L, :
## 'big.mark' and 'decimal.mark' are both '.', which could be confusing
p2
# p2 <- data_cases_sp_provincesX %>% filter( !(is.na(intensive_care) & date > as.Date("2020-08-10") ) ) %>%
# ggplot() +
# geom_line(aes(date, intensive_care,group=province, color=ccaa, text = paste0("<b>", province, " (", ccaa, ")</b><br>", format( round(intensive_care, digits = 1),
# big.mark=".", decimal.mark = ","), " UCI" ,"<br>",date )), size= 0.4) +
# scale_color_manual(values = colors_provX) +
# scale_y_log10( labels=function(x) format(round(x, digits = 0), big.mark = ".", scientific = FALSE),
# minor_breaks = c(seq(1 , 10, 1),seq(10 , 100, 10), seq(100 , 1000, 100), seq(1000 , 10000, 1000)),
# expand = c(0,0.1) ) +
# scale_x_date(date_breaks = "3 week",
# date_labels = "%d/%m",
# limits=c( min(data_cases_sp_provincesX$date)+7, max(data_cases_sp_provincesX$date )),
# expand = c(0,0)
# ) +
# theme_minimal(base_family = "Roboto Condensed",base_size = 16) +
# theme(
# panel.grid.minor.x = element_blank(),
# panel.grid.major.x = element_blank(),
# # panel.grid.minor.y = element_blank(),
# axis.ticks.x = element_line(color = "#000000"),
# legend.position = c(0.07,0.7)
# ) +
# labs(title = paste0("UCI (hospitalizados) por COVID-19 en España ", updated ),
# subtitle = paste0("Por provincia (escala logarítmica). ",period),
# y = "hospitalizados",
# x = "2020-2021",
# caption = caption_provincia)
#
#
# # save interactvive
# p2 <- ggplotly(p2, tooltip = "text") %>%
# layout(title = list(text = paste0('UCI (hospitalizados) por COVID-19 en España',
# '<br>',
# '<sup>',
# 'Por provincia (escala logarítmica)',
# '</sup>'))
# , annotations =
# list(x = 1, y = -0.11, text = "<a style='color:grey;' href='https://lab.montera34.com/covid19'>lab.montera34.com/covid19</a> | Data: <a style='color:grey;'href='https://github.com/montera34/escovid19data9'>esCOVID19data</a>",
# showarrow = F, xref='paper', yref='paper',
# xanchor='right', yanchor='auto', xshift=0, yshift=0,
# font=list(size=15, color="grey")
# ),
# legend = list(font = list(size = 10))
# )
#
# p2
p2 <- data_cases_sp_provincesX %>% filter( !(is.na(intensive_care) & date > as.Date("2020-08-10") ) ) %>%
ggplot() +
geom_line(aes(date, intensive_care/poblacion*1000000,group=province, color=ccaa, text = paste0("<b>", province, " (", ccaa, ")</b><br>", format( round(intensive_care/poblacion*1000000, digits = 1),
big.mark=".", decimal.mark = ","), " UCI" ,"<br>",date )), size= 0.4) +
scale_color_manual(values = colors_provX) +
scale_y_continuous( labels=function(x) format(round(x, digits = 0), big.mark = ".", scientific = FALSE),
# minor_breaks = c(seq(1 , 10, 1),seq(10 , 100, 10), seq(100 , 1000, 100), seq(1000 , 10000, 1000)),
expand = c(0,0.1) ) +
scale_x_date(date_breaks = "3 week",
date_labels = "%d/%m",
limits=c( min(data_cases_sp_provincesX$date)+7, max(data_cases_sp_provincesX$date )),
expand = c(0,0)
) +
theme_minimal(base_family = "Roboto Condensed",base_size = 16) +
theme(
panel.grid.minor.x = element_blank(),
panel.grid.major.x = element_blank(),
# panel.grid.minor.y = element_blank(),
axis.ticks.x = element_line(color = "#000000"),
legend.position = c(0.07,0.7)
) +
labs(title = paste0("UCI (hospitalizados) por COVID-19 en España por 100.000 habitantes ", updated ),
subtitle = paste0("Por provincia. ",period),
y = "hospitalizados",
x = "2020-2021",
caption = caption_provincia)
## Warning: Ignoring unknown aesthetics: text
# save interactvive
p2 <- ggplotly(p2, tooltip = "text") %>%
layout(title = list(text = paste0('UCI (hospitalizados) por COVID-19 en España por 100.000 habitantes',
'<br>',
'<sup>',
'Por provincia',
'</sup>'))
, annotations =
list(x = 1, y = -0.11, text = "<a style='color:grey;' href='https://lab.montera34.com/covid19'>lab.montera34.com/covid19</a> | Data: <a style='color:grey;'href='https://github.com/montera34/escovid19data9'>esCOVID19data</a>",
showarrow = F, xref='paper', yref='paper',
xanchor='right', yanchor='auto', xshift=0, yshift=0,
font=list(size=15, color="grey")
),
legend = list(font = list(size = 10))
)
## Warning in prettyNum(.Internal(format(x, trim, digits, nsmall, width, 3L, :
## 'big.mark' and 'decimal.mark' are both '.', which could be confusing
p2
### Periodo completo (rejilla)
# p2 <- data_cases_sp_provincesX %>% filter( ! ccaa %in% noprevalentes ) %>%
# ggplot() +
# geom_line(aes(date, hospitalized,group=province, color="black",
# text = paste0("<b>", province, " (", ccaa, ")</b><br>", format( round(hospitalized, digits = 1),
# big.mark=".", decimal.mark = ","), " hospitalizados" ,"<br>",date )
# ), size=0.8 ) +
# # geom_point(aes(date, hospitalized), size= 0.2 ) +
# geom_line(aes(date, intensive_care,group=province, color= "red",
# text = paste0("<b>", province, " (", ccaa, ")</b><br>", format( round(intensive_care, digits = 1),
# big.mark=".", decimal.mark = ","), " UCI" ,"<br>",date )
# ), size=0.8 ) +
# scale_color_identity(
# guide = "legend",
# labels = c("Hospitalizados","UCI"),
# ) +
# expand_limits(y = 0) +
# facet_wrap(~province, scales = "free_y") +
# scale_y_continuous(
# # limits = c(0,max(data_cases_sp_provincesX$cases_accumulated) ),
# labels=function(x) format(round(x, digits = 0), big.mark = ".", scientific = FALSE) ) +
# scale_x_date(date_breaks = "1 month",
# date_labels = "%m",
# limits=c( min(data_cases_sp_provincesX$date), max(data_cases_sp_provincesX$date)),
# expand = c(0,0)
# ) +
# theme_minimal(base_family = "Roboto Condensed",base_size = 8) +
# theme(
# panel.grid.minor.x = element_blank(),
# panel.grid.major.x = element_blank(),
# panel.grid.minor.y = element_blank(),
# axis.ticks.x = element_line(color = "#000000"),
# legend.position = "none",
# axis.text.x = element_text(size = 6)
# ) +
# labs(title = paste0("Hospitalizados y UCI por COVID-19 en España ", updated ),
# subtitle = paste0("Por provincia (escala lineal). ",period),
# y = "hospitalizados | UCI",
# x = "fecha (mes) 2020",
# color = "",
# caption = caption_provincia)
#
# # save interactvive
# p2 <- ggplotly(p2, tooltip = "text") %>%
# layout(title = list(text = paste0('Hospitalizados y UCI por COVID-19 en España',
# '<br>',
# '<sup>',
# 'Por provincia',
# '</sup>'))
# , annotations =
# list(x = 1, y = -0.11, text = "<a style='color:grey;' href='https://lab.montera34.com/covid19'>lab.montera34.com/covid19</a> | Data: <a style='color:grey;'href='https://github.com/montera34/escovid19data9'>esCOVID19data</a>",
# showarrow = F, xref='paper', yref='paper',
# xanchor='right', yanchor='auto', xshift=0, yshift=0,
# font=list(size=15, color="grey")
# )
# )
#
# p2
# ### Últimos 50 días (rejilla)
# p2 <- data_cases_sp_provincesX %>% filter( ! ccaa %in% noprevalentes ) %>% filter( date > filter_date - 50 ) %>%
# ggplot() +
# geom_line(aes(date, hospitalized,group=province, color="black",
# text = paste0("<b>", province, " (", ccaa, ")</b><br>", format( round(hospitalized, digits = 1),
# big.mark=".", decimal.mark = ","), " hospitalizados" ,"<br>",date )
# ), size=0.8 ) +
# # geom_point(aes(date, hospitalized), size= 0.2 ) +
# geom_line(aes(date, intensive_care,group=province, color= "red",
# text = paste0("<b>", province, " (", ccaa, ")</b><br>", format( round(intensive_care, digits = 1),
# big.mark=".", decimal.mark = ","), " UCI" ,"<br>",date )
# ), size=0.8 ) +
# scale_color_identity(
# guide = "legend",
# labels = c("Hospitalizados","UCI"),
# ) +
# expand_limits(y = 0) +
# facet_wrap(~province, scales = "free_y") +
# scale_y_continuous(
# # limits = c(0,max(data_cases_sp_provincesX$cases_accumulated) ),
# labels=function(x) format(round(x, digits = 0), big.mark = ".", scientific = FALSE) ) +
# scale_x_date(date_breaks = "1 month",
# date_labels = "%m",
# limits=c( filter_date - 50, max(data_cases_sp_provincesX$date)),
# expand = c(0,0)
# ) +
# theme_minimal(base_family = "Roboto Condensed",base_size = 8) +
# theme(
# panel.grid.minor.x = element_blank(),
# panel.grid.major.x = element_blank(),
# panel.grid.minor.y = element_blank(),
# axis.ticks.x = element_line(color = "#000000"),
# legend.position = "none",
# axis.text.x = element_text(size = 6)
# ) +
# labs(title = paste0("Hospitalizados y UCI por COVID-19 en España ", updated ),
# subtitle = paste0("Por provincia (escala lineal). ",period),
# y = "hospitalizados | UCI",
# x = "fecha (mes) 2020",
# color = "",
# caption = caption_provincia)
#
# # save interactvive
# p2 <- ggplotly(p2, tooltip = "text") %>%
# layout(title = list(text = paste0('Hospitalizados y UCI por COVID-19 en España',
# '<br>',
# '<sup>',
# 'Por provincia',
# '</sup>'))
# , annotations =
# list(x = 1, y = -0.11, text = "<a style='color:grey;' href='https://lab.montera34.com/covid19'>lab.montera34.com/covid19</a> | Data: <a style='color:grey;'href='https://github.com/montera34/escovid19data9'>esCOVID19data</a>",
# showarrow = F, xref='paper', yref='paper',
# xanchor='right', yanchor='auto', xshift=0, yshift=0,
# font=list(size=15, color="grey")
# )
# )
#
# p2
# Remove not prevalent hospitalized data for Murcia and Navarra early days
data_cases_sp_provinces <- readRDS(file = "../data/output/spain/covid19-provincias-spain_consolidated.rds")
data_cases_sp_provinces <- data_cases_sp_provinces %>% filter( (date > as.Date("2020-02-25") ) & ( date < filter_date ) )
# creates extended color palette https://www.r-bloggers.com/how-to-expand-color-palette-with-ggplot-and-rcolorbrewer/
colourCount <- length(unique(data_cases_sp_provincesX$ccaa))
getPalette <- colorRampPalette(brewer.pal(9, "Set1"))
colors_provX <- getPalette(colourCount )
# Change yellow to blue
colors_provX[1] <- "#a60000"
colors_provX[12] <- "#84d3e7"
p2 <- data_cases_sp_provincesX %>% filter( !(is.na(daily_deaths_avg7) & date > as.Date("2020-08-10") ) ) %>%
ggplot() +
geom_line(aes(date, daily_deaths_avg7,group=province, color=ccaa, text = paste0("<b>", province, " (", ccaa, ")</b><br>", format( round(daily_deaths_avg7, digits = 1),
big.mark=".", decimal.mark = ","), " fallecidos" ,"<br>",date )), size= 0.4) +
# geom_line(aes(date, intensive_care,group=province, text = paste0("<b>", province, " (", ccaa, ")</b><br>", format( round(intensive_care, digits = 1),
# big.mark=".", decimal.mark = ","), " UCI" ,"<br>",date )), size= 0.7, color = "grey") +
scale_color_manual(values = colors_provX) +
scale_y_continuous( labels=function(x) format(round(x, digits = 0), big.mark = ".", scientific = FALSE),
# minor_breaks = c(seq(1 , 10, 1),seq(10 , 100, 10), seq(100 , 1000, 100), seq(1000 , 10000, 1000)),
expand = c(0,0.1) ) +
scale_x_date(date_breaks = "3 week",
date_labels = "%d/%m",
limits=c( min(data_cases_sp_provincesX$date)+7, max(data_cases_sp_provincesX$date )),
expand = c(0,0)
) +
theme_minimal(base_family = "Roboto Condensed",base_size = 16) +
theme(
panel.grid.minor.x = element_blank(),
panel.grid.major.x = element_blank(),
# panel.grid.minor.y = element_blank(),
axis.ticks.x = element_line(color = "#000000"),
legend.position = c(0.07,0.7)
) +
labs(title = paste0("Fallecidos diarios por COVID-19 en España ", updated ),
subtitle = paste0("Por provincia. Media ventana de 7 días ",period),
y = "fallecidos",
x = "2020-2021",
caption = caption_provincia)
## Warning: Ignoring unknown aesthetics: text
# save interactvive
p2 <- ggplotly(p2, tooltip = "text") %>%
layout(title = list(text = paste0('Fallecidos diarios por COVID-19 en España',
'<br>',
'<sup>',
'Por provincia. Media ventana de 7 días ',
'</sup>'))
, annotations =
list(x = 1, y = -0.11, text = "<a style='color:grey;' href='https://lab.montera34.com/covid19'>lab.montera34.com/covid19</a> | Data: <a style='color:grey;'href='https://github.com/montera34/escovid19data9'>esCOVID19data</a>",
showarrow = F, xref='paper', yref='paper',
xanchor='right', yanchor='auto', xshift=0, yshift=0,
font=list(size=15, color="grey")
),
legend = list(font = list(size = 10))
)
## Warning in prettyNum(.Internal(format(x, trim, digits, nsmall, width, 3L, :
## 'big.mark' and 'decimal.mark' are both '.', which could be confusing
p2
p2 <- data_cases_sp_provincesX %>% filter( !(is.na(daily_deaths_avg7) & date > as.Date("2020-08-10") ) ) %>%
ggplot() +
geom_line(aes(date, daily_deaths_avg7,group=province, color=ccaa, text = paste0("<b>", province, " (", ccaa, ")</b><br>", format( round(daily_deaths_avg7, digits = 1),
big.mark=".", decimal.mark = ","), " fallecidos" ,"<br>",date )), size= 0.4) +
# geom_line(aes(date, intensive_care,group=province, text = paste0("<b>", province, " (", ccaa, ")</b><br>", format( round(intensive_care, digits = 1),
# big.mark=".", decimal.mark = ","), " UCI" ,"<br>",date )), size= 0.7, color = "grey") +
scale_color_manual(values = colors_provX) +
scale_y_log10( labels=function(x) format(round(x, digits = 0), big.mark = ".", scientific = FALSE),
minor_breaks = c(seq(1 , 10, 1),seq(10 , 100, 10), seq(100 , 1000, 100), seq(1000 , 10000, 1000)),
expand = c(0,0.1) ) +
scale_x_date(date_breaks = "3 week",
date_labels = "%d/%m",
limits=c( min(data_cases_sp_provincesX$date)+7, max(data_cases_sp_provincesX$date )),
expand = c(0,0)
) +
theme_minimal(base_family = "Roboto Condensed",base_size = 16) +
theme(
panel.grid.minor.x = element_blank(),
panel.grid.major.x = element_blank(),
# panel.grid.minor.y = element_blank(),
axis.ticks.x = element_line(color = "#000000"),
legend.position = c(0.07,0.7)
) +
labs(title = paste0("Fallecidos diarios por COVID-19 en España ", updated ),
subtitle = paste0("Por provincia (escala logarítmica). Media ventana de 7 días ",period),
y = "fallecidos",
x = "2020-2021",
caption = caption_provincia)
## Warning: Ignoring unknown aesthetics: text
# save interactvive
p2 <- ggplotly(p2, tooltip = "text") %>%
layout(title = list(text = paste0('Fallecidos diarios por COVID-19 en España',
'<br>',
'<sup>',
'Por provincia (escala logarítmica). Media ventana de 7 días ',
'</sup>'))
, annotations =
list(x = 1, y = -0.11, text = "<a style='color:grey;' href='https://lab.montera34.com/covid19'>lab.montera34.com/covid19</a> | Data: <a style='color:grey;'href='https://github.com/montera34/escovid19data9'>esCOVID19data</a>",
showarrow = F, xref='paper', yref='paper',
xanchor='right', yanchor='auto', xshift=0, yshift=0,
font=list(size=15, color="grey")
),
legend = list(font = list(size = 10))
)
## Warning in self$trans$transform(x): Se han producido NaNs
## Warning: Transformation introduced infinite values in continuous y-axis
## Warning in prettyNum(.Internal(format(x, trim, digits, nsmall, width, 3L, :
## 'big.mark' and 'decimal.mark' are both '.', which could be confusing
p2
p2 <- data_cases_sp_provincesX %>% filter( !(is.na(daily_deaths_avg7) & date > as.Date("2020-08-10") ) ) %>%
ggplot() +
geom_line(aes(date, daily_deaths_avg7/poblacion*100000,group=province, color=ccaa, text = paste0("<b>", province, " (", ccaa, ")</b><br>", format( round(daily_deaths_avg7/poblacion*100000, digits = 1),
big.mark=".", decimal.mark = ","), " fallecidos" ,"<br>",date )), size= 0.4) +
# geom_line(aes(date, intensive_care,group=province, text = paste0("<b>", province, " (", ccaa, ")</b><br>", format( round(intensive_care, digits = 1),
# big.mark=".", decimal.mark = ","), " UCI" ,"<br>",date )), size= 0.7, color = "grey") +
scale_color_manual(values = colors_provX) +
scale_y_continuous( labels=function(x) format(round(x, digits = 0), big.mark = ".", scientific = FALSE),
# minor_breaks = c(seq(1 , 10, 1),seq(10 , 100, 10), seq(100 , 1000, 100), seq(1000 , 10000, 1000)),
expand = c(0,0.1) ) +
scale_x_date(date_breaks = "3 week",
date_labels = "%d/%m",
limits=c( min(data_cases_sp_provincesX$date)+7, max(data_cases_sp_provincesX$date )),
expand = c(0,0)
) +
theme_minimal(base_family = "Roboto Condensed",base_size = 16) +
theme(
panel.grid.minor.x = element_blank(),
panel.grid.major.x = element_blank(),
# panel.grid.minor.y = element_blank(),
axis.ticks.x = element_line(color = "#000000"),
legend.position = c(0.07,0.7)
) +
labs(title = paste0("Fallecidos diarios por COVID-19 en España por 100.000 habitantes ", updated ),
subtitle = paste0("Por provincia. Media ventana de 7 días ",period),
y = "fallecidos",
x = "2020-2021",
caption = caption_provincia)
## Warning: Ignoring unknown aesthetics: text
# save interactvive
p2 <- ggplotly(p2, tooltip = "text") %>%
layout(title = list(text = paste0('Fallecidos diarios por COVID-19 en España por 100.000 habitantes',
'<br>',
'<sup>',
'Por provincia. Media ventana de 7 días ',
'</sup>'))
, annotations =
list(x = 1, y = -0.11, text = "<a style='color:grey;' href='https://lab.montera34.com/covid19'>lab.montera34.com/covid19</a> | Data: <a style='color:grey;'href='https://github.com/montera34/escovid19data9'>esCOVID19data</a>",
showarrow = F, xref='paper', yref='paper',
xanchor='right', yanchor='auto', xshift=0, yshift=0,
font=list(size=15, color="grey")
),
legend = list(font = list(size = 10))
)
## Warning in prettyNum(.Internal(format(x, trim, digits, nsmall, width, 3L, :
## 'big.mark' and 'decimal.mark' are both '.', which could be confusing
p2
Más información sobre los datos recopilados, en su mayorías de las comunidades autónomas, en esCOVID19data, proyecto colaborativo de recopilación de datos: https://github.com/montera34/escovid19data
Más visualizaciones en https://lab.montera34.com/covid19/provincias.html
Código de las visualizaciones realizadas en R: https://code.montera34.com/numeroteca/covid19/
Código en Rmarkdown de este dashboard en: https://code.montera34.com:4443/numeroteca/covid19/-/blob/master/dashboard/index.Rmd
Visualizaciones realizadas por @numeroteca y alojadas en Montera34.com.
Realizado por Montera34, disponible bajo licencia GNU GPL 3 y CC BY SA | Código para generar los gráficos | Datos | Contacto | @montera34.