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 E.
En primer lugar, se descargan los shapes de vacuntarios y de Municipios des 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)
## 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)
## 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()
Para poder estimar distancias vamos a calcular la distancia del centroide de los Municipios 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)
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()
vacunatorios <- vacunatorios %>%
mutate(lat = unlist(map(vacunatorios$geometry,1)),
long = unlist(map(vacunatorios$geometry,2)))
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_E <- vacunatorios %>%
mutate (NOMBRE_ORIGEN="MUNICIPIO E") %>%
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_E)
## Simple feature collection with 6 features and 6 fields
## Geometry type: POINT
## Dimension: XYZ
## Bounding box: xmin: 568360 ymin: 6137518 xmax: 580606 ymax: 6148579
## z_range: zmin: 0 zmax: 0
## Projected CRS: WGS 84 / UTM zone 21S
## NOMBRE_ORIGEN LON_ORIGEN LAT_ORIGEN NOMBRE_DESTINO
## 1 MUNICIPIO E NA NA CENTRO DE SALUD CERRO JX035
## 2 MUNICIPIO E NA NA ASOCIACIÓN ESPAÑOLA JX036
## 3 MUNICIPIO E NA NA ASOCIACIÓN ESPAÑOLA 2 JX045
## 4 MUNICIPIO E NA NA IMM COMPLEJO CRECE JX034
## 5 MUNICIPIO E NA NA C.A.P. GRUPO DE ARTILLERÍA NO. 1 JX0048
## 6 MUNICIPIO E NA NA COLEGIO MÉDICO JX045
## LON_DESTINO LAT_DESTINO geometry
## 1 6140697 568360 POINT Z (568360 6140697 0)
## 2 6148579 570978 POINT Z (570978 6148579 0)
## 3 6137518 576260 POINT Z (576260 6137518 0)
## 4 6142973 580606 POINT Z (580606 6142973 0)
## 5 6142273 568362 POINT Z (568362 6142273 0)
## 6 6138288 576652 POINT Z (576652 6138288 0)
Muni_E <- mutate(Muni_E,LON_ORIGEN=583199.1, LAT_ORIGEN=6139526)%>%
mutate (LON_ORIGEN=as.integer(LON_ORIGEN),LAT_ORIGEN=as.integer(LAT_ORIGEN))
head(Muni_E)
## Simple feature collection with 6 features and 6 fields
## Geometry type: POINT
## Dimension: XYZ
## Bounding box: xmin: 568360 ymin: 6137518 xmax: 580606 ymax: 6148579
## z_range: zmin: 0 zmax: 0
## Projected CRS: WGS 84 / UTM zone 21S
## NOMBRE_ORIGEN LON_ORIGEN LAT_ORIGEN NOMBRE_DESTINO
## 1 MUNICIPIO E 583199 6139526 CENTRO DE SALUD CERRO JX035
## 2 MUNICIPIO E 583199 6139526 ASOCIACIÓN ESPAÑOLA JX036
## 3 MUNICIPIO E 583199 6139526 ASOCIACIÓN ESPAÑOLA 2 JX045
## 4 MUNICIPIO E 583199 6139526 IMM COMPLEJO CRECE JX034
## 5 MUNICIPIO E 583199 6139526 C.A.P. GRUPO DE ARTILLERÍA NO. 1 JX0048
## 6 MUNICIPIO E 583199 6139526 COLEGIO MÉDICO JX045
## LON_DESTINO LAT_DESTINO geometry
## 1 6140697 568360 POINT Z (568360 6140697 0)
## 2 6148579 570978 POINT Z (570978 6148579 0)
## 3 6137518 576260 POINT Z (576260 6137518 0)
## 4 6142973 580606 POINT Z (580606 6142973 0)
## 5 6142273 568362 POINT Z (568362 6142273 0)
## 6 6138288 576652 POINT Z (576652 6138288 0)
ruteo_E <- list(Muni_E$NOMBRE_ORIGEN, Muni_E$LON_ORIGEN,Muni_E$LAT_ORIGEN,
Muni_E$NOMBRE_DESTINO, Muni_E$LON_DESTINO,Muni_E$LAT_DESTINO)
ruteo_1 <- pmap(ruteo_E, ruteo_vacunatorio) %>%
reduce(rbind)
## The OSRM server returned an error:
## Error: InvalidQuery
## Query string malformed close to position 18
##
## The OSRM server returned an error:
## Error: InvalidQuery
## Query string malformed close to position 18
##
## The OSRM server returned an error:
## Error: InvalidQuery
## Query string malformed close to position 18
##
## The OSRM server returned an error:
## Error: InvalidQuery
## Query string malformed close to position 18
##
## The OSRM server returned an error:
## Error: InvalidQuery
## Query string malformed close to position 18
##
## The OSRM server returned an error:
## Error: InvalidQuery
## Query string malformed close to position 18
##
## The OSRM server returned an error:
## Error: InvalidQuery
## Query string malformed close to position 18
##
## The OSRM server returned an error:
## Error: InvalidQuery
## Query string malformed close to position 18
##
## The OSRM server returned an error:
## Error: InvalidQuery
## Query string malformed close to position 18
##
## The OSRM server returned an error:
## Error: InvalidQuery
## Query string malformed close to position 18
##
## The OSRM server returned an error:
## Error: InvalidQuery
## Query string malformed close to position 18
##
## The OSRM server returned an error:
## Error: InvalidQuery
## Query string malformed close to position 18
##
## The OSRM server returned an error:
## Error: InvalidQuery
## Query string malformed close to position 18
##
## The OSRM server returned an error:
## Error: InvalidQuery
## Query string malformed close to position 18
##
## The OSRM server returned an error:
## Error: InvalidQuery
## Query string malformed close to position 18
##
## The OSRM server returned an error:
## Error: InvalidQuery
## Query string malformed close to position 18
##
## The OSRM server returned an error:
## Error: InvalidQuery
## Query string malformed close to position 18
##
## The OSRM server returned an error:
## Error: InvalidQuery
## Query string malformed close to position 18
##
## The OSRM server returned an error:
## Error: InvalidQuery
## Query string malformed close to position 18
##
## The OSRM server returned an error:
## Error: InvalidQuery
## Query string malformed close to position 18
##
## The OSRM server returned an error:
## Error: InvalidQuery
## Query string malformed close to position 18
##
## The OSRM server returned an error:
## Error: InvalidQuery
## Query string malformed close to position 18
##
## The OSRM server returned an error:
## Error: InvalidQuery
## Query string malformed close to position 18
##
## The OSRM server returned an error:
## Error: InvalidQuery
## Query string malformed close to position 18
##
## The OSRM server returned an error:
## Error: InvalidQuery
## Query string malformed close to position 18
##
## The OSRM server returned an error:
## Error: InvalidQuery
## Query string malformed close to position 18
##
## The OSRM server returned an error:
## Error: InvalidQuery
## Query string malformed close to position 18
##
## The OSRM server returned an error:
## Error: InvalidQuery
## Query string malformed close to position 18