Distancias a vacunatorios para inmunización COVID-19

library(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.0.5
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.3     v purrr   0.3.4
## v tibble  3.1.1     v dplyr   1.0.5
## v tidyr   1.1.3     v stringr 1.4.0
## v readr   1.4.0     v forcats 0.5.1
## Warning: package 'ggplot2' was built under R version 4.0.5
## Warning: package 'tibble' was built under R version 4.0.5
## Warning: package 'tidyr' was built under R version 4.0.5
## Warning: package 'readr' was built under R version 4.0.5
## Warning: package 'dplyr' was built under R version 4.0.5
## Warning: package 'forcats' was built under R version 4.0.5
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(sf)
## Warning: package 'sf' was built under R version 4.0.5
## Linking to GEOS 3.9.0, GDAL 3.2.1, PROJ 7.2.1
library(ggmap)
## Warning: package 'ggmap' was built under R version 4.0.5
## Google's Terms of Service: https://cloud.google.com/maps-platform/terms/.
## Please cite ggmap if you use it! See citation("ggmap") for details.
library(leaflet)
## Warning: package 'leaflet' was built under R version 4.0.5
library(osrm)
## Warning: package 'osrm' was built under R version 4.0.5
## Data: (c) OpenStreetMap contributors, ODbL 1.0 - http://www.openstreetmap.org/copyright
## Routing: OSRM - http://project-osrm.org/
## sp support will be dropped in the next major release, please use sf objects instead.

Con el objetivo de analizar si existen barreras al acceso a la vacunación para COVID-19 vinculadas a la accesibilidad de los vacunatorios se estudiarán las distancias desde los vacunatorios al Municipio D.

En primer lugar, se descargan los shapes de vacuntarios y de Municipios de la página de la Intendencia de Montevideo (https://sig.montevideo.gub.uy/) y se presenta un mapa mostrando la distribución terroritorial de los vacunatorios en Montevideo.

vacunatorios <-st_read ("VACUNATORIOS_MSP_COVID_UTM.shp", stringsAsFactors = TRUE) %>%
st_transform(crs = 4326) 
## Reading layer `VACUNATORIOS_MSP_COVID_UTM' from data source 
##   `C:\Users\Usuario\Documents\Diplomatura\Ciencia_datos_ciudades\Datos_ciudades\Tareas\VACUNATORIOS_MSP_COVID_UTM.shp' 
##   using driver `ESRI Shapefile'
## Simple feature collection with 28 features and 3 fields
## Geometry type: POINT
## Dimension:     XYZ
## Bounding box:  xmin: 568360 ymin: 6136809 xmax: 582570 ymax: 6148579
## z_range:       zmin: 0 zmax: 0
## Projected CRS: WGS 84 / UTM zone 21S
Municipios <- st_read("sig_municipios.shp", stringsAsFactors = TRUE) %>%
st_transform(crs = 4326) 
## Reading layer `sig_municipios' from data source 
##   `C:\Users\Usuario\Documents\Diplomatura\Ciencia_datos_ciudades\Datos_ciudades\Tareas\sig_municipios.shp' 
##   using driver `ESRI Shapefile'
## Simple feature collection with 8 features and 5 fields
## Geometry type: POLYGON
## Dimension:     XY
## Bounding box:  xmin: 551994.3 ymin: 6133494 xmax: 589199.4 ymax: 6159799
## Projected CRS: WGS 84 / UTM zone 21S
ggplot() +
  geom_sf(data=Municipios)+
  geom_sf_text (data=Municipios, aes(label=MUNICIPIO), size=4)+
  geom_sf(data=vacunatorios, color="turquoise4", size=3)+
  labs(title="Vacunatorios COVID-19 por Municipio",
       subtitle=" Montevideo",
       caption = "Fuente: SIG de Intendencia de Montevideo",
      fill="Población") +
    theme_void()
## Warning in st_point_on_surface.sfc(sf::st_zm(x)): st_point_on_surface may not
## give correct results for longitude/latitude data

Para poder estimar distancias vamos a calcular la distancia del centroide del Municipio D a los vacunatorios. Por tanto, primero generaremos un mapa con los centroides de los Municipios y transformaremos la geometría en coordenadas para poder luego calcular distancias.

Munis_ptos <- Municipios %>%
  st_centroid()  
## Warning in st_centroid.sf(.): st_centroid assumes attributes are constant over
## geometries of x
Munis_ptos <- cbind(Munis_ptos, st_coordinates(Munis_ptos)) %>%
                      st_set_geometry(NULL) %>% 
                      rename(LON_ORIGEN=X,
                             LAT_ORIGEN=Y)

En el siguiente mapa se visualizan los centroides de los Municipios, los límites de los Municipios y los vacunatorios.

ggplot()+
  geom_sf(data=Municipios)+
  geom_sf_text (data=Municipios, aes(label=MUNICIPIO), size=4)+
  geom_sf(data=vacunatorios, color="turquoise4", size=3)+
  geom_point(data=Munis_ptos, aes(x=LON_ORIGEN, y=LAT_ORIGEN), color="red", shape=4, size=2)+
  labs(title="Vacunatorios COVID-19 por Municipio",
       subtitle=" Montevideo",
      caption = "Fuente: SIG de Intendencia de Montevideo",
      fill="Población") +
  theme_void()
## Warning in st_point_on_surface.sfc(sf::st_zm(x)): st_point_on_surface may not
## give correct results for longitude/latitude data

vacunatorios <- vacunatorios %>%
mutate(lat = unlist(map(vacunatorios$geometry,2)),
long = unlist(map(vacunatorios$geometry,1)))
ruteo_vacunatorio <- function(o_nombre, o_x, o_y, d_nombre, d_x, d_y) {
  ruta <- osrmRoute(src = c(o_nombre, o_x, o_y),
                    dst = c(d_nombre, d_x, d_y), 
                    returnclass = "sf",
                    overview = "full")
  
  cbind(ORIGEN = o_nombre, DESTINO = d_nombre, ruta)
}
Muni_D <- vacunatorios %>%
  mutate (NOMBRE_ORIGEN="MUNICIPIO D") %>%
  left_join(Munis_ptos, by=c("NOMBRE_ORIGEN"="MUNICIPIO")) %>%
  rename(NOMBRE_DESTINO=Name,
         LON_DESTINO=long,
         LAT_DESTINO=lat) %>%
  select(NOMBRE_ORIGEN, LON_ORIGEN, LAT_ORIGEN, NOMBRE_DESTINO, LON_DESTINO, LAT_DESTINO)
head(Muni_D)
## Simple feature collection with 6 features and 6 fields
## Geometry type: POINT
## Dimension:     XYZ
## Bounding box:  xmin: -56.25212 ymin: -34.9019 xmax: -56.11826 ymax: -34.80255
## z_range:       zmin: 0 zmax: 0
## Geodetic CRS:  WGS 84
##   NOMBRE_ORIGEN LON_ORIGEN LAT_ORIGEN                          NOMBRE_DESTINO
## 1   MUNICIPIO D         NA         NA             CENTRO DE SALUD CERRO JX035
## 2   MUNICIPIO D         NA         NA               ASOCIACIÓN ESPAÑOLA JX036
## 3   MUNICIPIO D         NA         NA             ASOCIACIÓN ESPAÑOLA 2 JX045
## 4   MUNICIPIO D         NA         NA                IMM COMPLEJO CRECE JX034
## 5   MUNICIPIO D         NA         NA C.A.P. GRUPO DE ARTILLERÍA NO. 1 JX0048
## 6   MUNICIPIO D         NA         NA                    COLEGIO MÉDICO JX045
##   LON_DESTINO LAT_DESTINO                       geometry
## 1   -56.25202   -34.87380 POINT Z (-56.25202 -34.8738 0)
## 2   -56.22404   -34.80255 POINT Z (-56.22404 -34.8025...
## 3   -56.16529   -34.90190 POINT Z (-56.16529 -34.9019 0)
## 4   -56.11826   -34.85238 POINT Z (-56.11826 -34.8523...
## 5   -56.25212   -34.85959 POINT Z (-56.25212 -34.8595...
## 6   -56.16107   -34.89493 POINT Z (-56.16107 -34.8949...
Muni_D <- mutate(Muni_D,LON_ORIGEN=-56.14990, LAT_ORIGEN=-34.78790)%>% 
    mutate (LON_ORIGEN=as.numeric(LON_ORIGEN),LAT_ORIGEN=as.numeric(LAT_ORIGEN))
head(Muni_D)
## Simple feature collection with 6 features and 6 fields
## Geometry type: POINT
## Dimension:     XYZ
## Bounding box:  xmin: -56.25212 ymin: -34.9019 xmax: -56.11826 ymax: -34.80255
## z_range:       zmin: 0 zmax: 0
## Geodetic CRS:  WGS 84
##   NOMBRE_ORIGEN LON_ORIGEN LAT_ORIGEN                          NOMBRE_DESTINO
## 1   MUNICIPIO D   -56.1499   -34.7879             CENTRO DE SALUD CERRO JX035
## 2   MUNICIPIO D   -56.1499   -34.7879               ASOCIACIÓN ESPAÑOLA JX036
## 3   MUNICIPIO D   -56.1499   -34.7879             ASOCIACIÓN ESPAÑOLA 2 JX045
## 4   MUNICIPIO D   -56.1499   -34.7879                IMM COMPLEJO CRECE JX034
## 5   MUNICIPIO D   -56.1499   -34.7879 C.A.P. GRUPO DE ARTILLERÍA NO. 1 JX0048
## 6   MUNICIPIO D   -56.1499   -34.7879                    COLEGIO MÉDICO JX045
##   LON_DESTINO LAT_DESTINO                       geometry
## 1   -56.25202   -34.87380 POINT Z (-56.25202 -34.8738 0)
## 2   -56.22404   -34.80255 POINT Z (-56.22404 -34.8025...
## 3   -56.16529   -34.90190 POINT Z (-56.16529 -34.9019 0)
## 4   -56.11826   -34.85238 POINT Z (-56.11826 -34.8523...
## 5   -56.25212   -34.85959 POINT Z (-56.25212 -34.8595...
## 6   -56.16107   -34.89493 POINT Z (-56.16107 -34.8949...
ruteo_D <- list(Muni_D$NOMBRE_ORIGEN, Muni_D$LON_ORIGEN,Muni_D$LAT_ORIGEN,
                   Muni_D$NOMBRE_DESTINO, Muni_D$LON_DESTINO,Muni_D$LAT_DESTINO)

ruteo_1 <- pmap(ruteo_D, ruteo_vacunatorio) %>% 
  reduce(rbind)
ruteo_1 %>% 
summary()
##     ORIGEN                                              DESTINO  
##  Length:28          ANTEL ARENA JX001 AL JX005              : 1  
##  Class :character   ASOCIACIÓN ESPAÑOLA 2 JX045             : 1  
##  Mode  :character   ASOCIACIÓN ESPAÑOLA JX023               : 1  
##                     ASOCIACIÓN ESPAÑOLA JX036               : 1  
##                     C.A.P. BRIGADA DE INFANTERÍA NO. 1 JX047: 1  
##                     C.A.P. GRUPO DE ARTILLERÍA NO. 1 JX0048 : 1  
##                     (Other)                                 :22  
##      src                 dst           duration        distance    
##  Length:28          Min.   : 1.00   Min.   :11.50   Min.   : 8.65  
##  Class :character   1st Qu.: 7.75   1st Qu.:16.28   1st Qu.:11.24  
##  Mode  :character   Median :14.50   Median :20.23   Median :13.65  
##                     Mean   :14.50   Mean   :19.41   Mean   :13.41  
##                     3rd Qu.:21.25   3rd Qu.:22.91   3rd Qu.:15.24  
##                     Max.   :28.00   Max.   :27.63   Max.   :18.72  
##                                                                    
##           geometry 
##  LINESTRING   :28  
##  epsg:4326    : 0  
##  +proj=long...: 0  
##                    
##                    
##                    
## 

Luego de calcular el ruteo de cada vacunatorio al Municipio D, es posible decir que la media de tiempo de trasalado desde el Municipio D a un vacunatorio COVID-19 es 19,41 minutos. El vacunatorio más cercano a ese Municipio es la Policlínica Zully Sánchez de la Intendencia de Montevideo.

filter(ruteo_1, distance == min(distance))$DESTINO
## [1] IMM POLICLINICA ZULLY SÁNCHEZ JX033
## 28 Levels: ANTEL ARENA JX001 AL JX005 ... UNIVERSAL JX021
paleta <- c(low="gold", high= "deeppink4")

icons_d <- awesomeIcons(icon = "Vaunatorio",
                      iconColor = "black",
                      library = "fa",
                      markerColor = "red")

icons_o <- awesomeIcons(icon = "whatever",
                      iconColor = "black",
                      library = "fa",
                      markerColor = "gray")


mapaRuteo1 <- leaflet(ruteo_1) %>%
   addTiles() %>% 
   addPolylines(color = ~colorNumeric(paleta, ruteo_1$distance)(distance),
                 label = paste("Distancia:", ruteo_1$distance, "|", 
                               "Duración:", ruteo_1$duration))
mapaRuteo1