---
title: "Día 14 #30díasdegráficos (Treemaps). Muertes por COVID-19 a 05-06-2020"
output:
flexdashboard::flex_dashboard:
storyboard: true
orientation: columns
source_code: embed
vertical_layout: fill
theme: paper
---
```{r setup, include=FALSE}
# PACKAGES / LIBRARIES:
library(flexdashboard)
library(tidyverse)
library(treemap)
library(d3treeR)
library(highcharter)
library(readxl)
library(stringr)
library(knitr)
library(DT)
library(viridisLite)
library(reshape2)
library(openxlsx)
library(RColorBrewer)
options(scipen=10000)
## FUENTE: https://github.com/montera34/escovid19data
covid <- read_csv("https://raw.githubusercontent.com/montera34/escovid19data/master/data/output/covid19-provincias-spain_consolidated.csv")
covid_tree <- covid %>%
mutate(provincia = if_else(province == "Balears, Illes", "Balears, Illes.", province)) %>%
mutate(provincia = if_else(province == "Ceuta", "Ceuta.", provincia)) %>%
mutate(provincia = if_else(province == "Melilla", "Melilla.", provincia)) %>%
mutate(provincia = if_else(province == "Rioja, La", "Rioja, La.", provincia))%>%
mutate(provincia = if_else(province == "Cantabria", "Cantabria.", provincia))%>%
dplyr::select(provincia, ccaa, deceased) %>%
group_by(provincia) %>%
summarise_all(funs(max), na.rm = TRUE)
covid_tree <- as.data.frame(covid_tree)
```
Treemap estático
====================================================================================
### Example I. Static Treemap
```{r, fig.width=14, fig.height=8}
tree_covid <- treemap(
covid_tree,
index = c("ccaa", "provincia"),
vSize="deceased",
title = "Fallecimientos por COVID-19 (actualizado a 05-06-2020)",
vColor="ccaa",
type="index",
force.print.labels = F,
border.col = c("black", "white"),
border.lwds = c(3,2),
align.labels = list(
c("center","center"),
c("center", "top")
)
)
```
Comunidades Autónomas y Provincias
====================================================================================
### Example II. Comunidades Autónomas y Provincias
```{r}
hctreemap(tree_covid, allowDrillToNode = TRUE) %>%
hc_title(text = "") %>%
hc_tooltip(pointFormat = "{point.name}:
Fallecimientos: {point.value:,.0f}") %>%
hc_exporting(enabled = TRUE)
```
Comunidades Autónomas
====================================================================================
### Example III. Comunidades Autónomas
```{r}
hctreemap2(data = as.data.frame(covid_tree),
group_vars = c("ccaa"),
size_var = "deceased",
color_var = "deceased",
layoutAlgorithm = "squarified",
levelIsConstant = FALSE) %>%
hc_colorAxis(minColor = brewer.pal(7, "Greens")[1],
maxColor = brewer.pal(7, "Greens")[7]) %>%
hc_tooltip(pointFormat = "{point.name}:
Fallecidos: {point.value:,.0f}")
```
Provincias
====================================================================================
### Example IV. Provincias
```{r}
hctreemap2(data = as.data.frame(covid_tree),
group_vars = c("provincia"),
size_var = "deceased",
color_var = "deceased",
layoutAlgorithm = "squarified",
levelIsConstant = FALSE) %>%
hc_colorAxis(minColor = brewer.pal(7, "Oranges")[1],
maxColor = brewer.pal(7, "Oranges")[7]) %>%
hc_tooltip(pointFormat = "{point.name}:
Fallecidos: {point.value:,.0f}")
```