library(tidyverse)
library(sf)
library(ggmap)
library(osrm)
library(leaflet)

Para este trabajo analizaremos las distancias desde los centroides de los barrios Downtown (céntrico) y Warrendale (periférico) a los hospitales de la ciudad de Detroit. Para eso cargamos los hospitales y los barrios:

hospitales <- st_read("8f8147bc-6999-483c-a589-ec8b2ec831c22020329-1-1iv4wkx.mf0q.shp")
## Reading layer `8f8147bc-6999-483c-a589-ec8b2ec831c22020329-1-1iv4wkx.mf0q' from data source `F:\Sistema\Usr\Documents\Datos 2020\II\8f8147bc-6999-483c-a589-ec8b2ec831c22020329-1-1iv4wkx.mf0q.shp' using driver `ESRI Shapefile'
## Simple feature collection with 8 features and 8 fields
## geometry type:  POINT
## dimension:      XY
## bbox:           xmin: -83.18413 ymin: 42.35067 xmax: -82.91634 ymax: 42.42052
## CRS:            4326
barrios <- st_read("Neighborhoods.shp")
## Reading layer `Neighborhoods' from data source `F:\Sistema\Usr\Documents\Datos 2020\II\Neighborhoods.shp' using driver `ESRI Shapefile'
## Simple feature collection with 208 features and 16 fields
## geometry type:  POLYGON
## dimension:      XY
## bbox:           xmin: -83.28785 ymin: 42.25519 xmax: -82.91056 ymax: 42.45023
## CRS:            4326

Encontramos los centroides de los barrios

barrios_centroides <- barrios %>%
  st_centroid()

Y los graficamos

ggplot()+
  geom_sf(data=barrios, fill="lightyellow")+
  geom_sf(data=barrios_centroides, size=2)+
  labs(title = "Barrios de Detroit",
         subtitle = "Ubicación de los centroides",
         fill="Barrios",
         caption= "Fuente:https://https://data.detroitmi.gov//")+
  theme_void()