Column

Mapa de Proporción de Internet


Mapa de Proporción de Energía

Row

Mapa de Proporción de Acueducto


Mapa de Proporción de Alcantrillado


Datos de los Municipios

---
title: "Dashboard de Bolívar"
author: "Juan Carlos Quintero"
output: 
  flexdashboard::flex_dashboard:
    orientation: rows
    vertical_layout: fill
    source_code: embed
---


```{r setup, include=FALSE}
# Cargar librerías necesarias
library(leaflet)
library(dplyr)
library(ggplot2)
library(sf)
library(DT)
library(flexdashboard)
library(readr)
```


```{r, include=FALSE}
# Leer el archivo shapefile usando sf
bolivar_sf <- st_read('C:/Users/juanc/Documents/Semestre 5/Visualización/Actividad4/SHP_MGN2018_INTGRD_MPIO/MGN_ANM_MPIOS.shp')
```
```{r load_data, include=FALSE}
# Filtrar los municipios del departamento de Bolívar
bolivar_sf <- bolivar_sf %>% filter(DPTO_CCDGO == '13')
```


```{r, include=FALSE}
# Crear nuevas variables a partir de los datos
bolivar_sf <- bolivar_sf %>%
  mutate(prop_internet = STP19_INT1 / (STP19_INT1 + STP19_INT2)) %>%
  mutate(nivel_educativo = case_when(
    STP51_PRIM > STP51_SECU & STP51_PRIM > STP51_SUPE & STP51_PRIM > STP51_POST ~ "Primaria",
    STP51_SECU > STP51_PRIM & STP51_SECU > STP51_SUPE & STP51_SECU > STP51_POST ~ "Secundaria",
    STP51_SUPE > STP51_PRIM & STP51_SUPE > STP51_SECU & STP51_SUPE > STP51_POST ~ "Superior",
    STP51_POST > STP51_PRIM & STP51_POST > STP51_SECU & STP51_POST > STP51_SUPE ~ "Posgrado",
    TRUE ~ "Indeterminado"
  )) %>%
  mutate(prop_energia = STP19_EC_1 / (STP19_EC_1 + STP19_ES_2)) %>%
  mutate(prop_acueducto = STP19_ACU1 / (STP19_ACU1 + STP19_ACU2)) %>%
  mutate(prop_alcantarillado = STP19_ALC1 / (STP19_ALC1 + STP19_ALC2))
```

```{r, include=FALSE}
# Cargar datos adicionales de los municipios desde un archivo CSV
municipios_dane <- read_delim("C:/Users/juanc/Documents/Semestre 5/Visualización/Actividad4/SHP_MGN2018_INTGRD_MPIO/Codigos_DaneV2.csv", delim = ";", locale = locale(encoding = "latin1"))
municipios_bolivar <- municipios_dane %>% filter(grepl("^13", DANE))
```

```{r, include=FALSE}
# Unir los datos de municipios con el shapefile de Bolívar
bolivar_sf <- left_join(bolivar_sf, municipios_bolivar, by = c("MPIO_CCDGO" = "DANE"))
```


```{r, include=FALSE}
# Verificar los datos
head(bolivar_sf)
```


Column {.tabset}
-----------------------------------------------------------------------

### Mapa de Proporción de Internet

```{r}
# Seleccionar la variable a visualizar
variable <- "prop_internet"

# Crear paleta de colores para el mapa
pal <- colorNumeric("viridis", domain = bolivar_sf[[variable]], na.color = "transparent")

# Crear el mapa
leaflet(bolivar_sf) %>%
  addTiles() %>%
  addPolygons(
    fillColor = ~pal(bolivar_sf[[variable]]),
    fillOpacity = 0.7,
    color = "white",
    weight = 1,
    popup = ~paste("Municipio:", MPIO_CNMBR, "<br>", variable, ":", bolivar_sf[[variable]])
  ) %>%
  addLegend(pal = pal, values = ~bolivar_sf[[variable]], opacity = 0.7, title = variable)
```





-----------------------------------------------------------------------

### Mapa de Proporción de Energía

```{r}
variable <- "prop_energia"
pal <- colorNumeric("viridis", domain = bolivar_sf[[variable]], na.color = "transparent")

leaflet(bolivar_sf) %>%
  addTiles() %>%
  addPolygons(
    fillColor = ~pal(bolivar_sf[[variable]]),
    fillOpacity = 0.7,
    color = "white",
    weight = 1,
    popup = ~paste("Municipio:", MPIO_CNMBR, "<br>", "Proporcion de Energia:", bolivar_sf[[variable]])
  ) %>%
  addLegend(pal = pal, values = ~bolivar_sf[[variable]], opacity = 0.7, title = "Proporcion de Energia")

```


Row {.tabset .tabset-fade}
-----------------------------------------------------------------------

### Mapa de Proporción de Acueducto

```{r}
variable <- "prop_acueducto"
pal <- colorNumeric("viridis", domain = bolivar_sf[[variable]], na.color = "transparent")

leaflet(bolivar_sf) %>%
  addTiles() %>%
  addPolygons(
    fillColor = ~pal(bolivar_sf[[variable]]),
    fillOpacity = 0.7,
    color = "white",
    weight = 1,
    popup = ~paste("Municipio:", MPIO_CNMBR, "<br>", "Proporcion de Acueducto:", bolivar_sf[[variable]])
  ) %>%
  addLegend(pal = pal, values = ~bolivar_sf[[variable]], opacity = 0.7, title = "Proporcion de Acueducto")

```



-----------------------------------------------------------------------

### Mapa de Proporción de Alcantrillado

```{r}
variable <- "prop_alcantarillado"
pal <- colorNumeric("viridis", domain = bolivar_sf[[variable]], na.color = "transparent")

leaflet(bolivar_sf) %>%
  addTiles() %>%
  addPolygons(
    fillColor = ~pal(bolivar_sf[[variable]]),
    fillOpacity = 0.7,
    color = "white",
    weight = 1,
    popup = ~paste("Municipio:", MPIO_CNMBR, "<br>", "Proporcion de Alcantarillado:", bolivar_sf[[variable]])
  ) %>%
  addLegend(pal = pal, values = ~bolivar_sf[[variable]], opacity = 0.7, title = "Proporcion de Alcantarillado")

```




-----------------------------------------------------------------------

### Datos de los Municipios

```{r}
# Crear una tabla interactiva con los datos de los municipios
datatable(bolivar_sf %>% st_drop_geometry() %>% as.data.frame())

```