library(osmdata)
## Data (c) OpenStreetMap contributors, ODbL 1.0. https://www.openstreetmap.org/copyright
library(leaflet)
library(tidyverse)
## -- Attaching packages -------------- tidyverse 1.3.0 --
## v ggplot2 3.3.0 v purrr 0.3.4
## v tibble 3.0.1 v dplyr 0.8.5
## v tidyr 1.0.2 v stringr 1.4.0
## v readr 1.3.1 v forcats 0.5.0
## -- Conflicts ----------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(sf)
## Linking to GEOS 3.6.1, GDAL 2.2.3, PROJ 4.9.3
I. Descargamos de OpenStreetMap la grilla de calles para la Ciudad de Rosario y la mapeamos por uno de sus atributos: cantidad de carriles.
bbox <- getbb("Rosario, Santa Fe")
bbox
## min max
## x -60.78326 -60.61167
## y -33.03487 -32.86965
bbox_poly <- getbb("Municipio de Rosario, Santa Fe", format_out = "sf_polygon")
leaflet(bbox_poly) %>%
addTiles() %>%
addPolygons()
rosario <- opq(bbox) %>%
add_osm_feature(key = "highway")
rosario <- rosario %>%
osmdata_sf()
calles <- rosario$osm_lines
calles <- st_intersection(calles, bbox_poly)
## although coordinates are longitude/latitude, st_intersection assumes that they are planar
## Warning: attribute variables are assumed to be spatially constant throughout all
## geometries
ggplot() +
geom_sf(data = calles)

calles <- calles %>%
mutate(lanes = ifelse(is.na(lanes), 1, as.numeric(lanes)))
En el último paso graficamos el ancho de los carriles para la ciudad de Rosario y consideramos los campos na = un carril.
ggplot(calles) +
geom_sf(aes(color = lanes), alpha = 0.5) +
scale_color_viridis_c() +
theme_void() +
labs(title = "Rosario",
subtitle = "Vías de circulación",
caption = "fuente: OpenStreetMap",
color = "ancho de carriles")

II a. Descargamos de OpenStreetMap la capa farmacias. Proyectamos los datos descargados en el mapa.
bbox_st <- getbb('Rosario, Argentina')
bbox_st_poly = getbb('Rosario, Argentina', format_out = "sf_polygon")
leaflet(bbox_st_poly) %>%
addTiles() %>%
addPolygons()
rosario_calles <- opq(bbox_st) %>%
add_osm_feature(key = "highway") %>%
osmdata_sf()
rosario_farmacia <- opq(bbox_st) %>%
add_osm_feature(key = "amenity", value = "pharmacy") %>%
osmdata_sf()
rosario_calles <- st_intersection(rosario_calles$osm_lines, bbox_st_poly)
## although coordinates are longitude/latitude, st_intersection assumes that they are planar
## Warning: attribute variables are assumed to be spatially constant throughout all
## geometries
rosario_farmacia <- st_intersection(rosario_farmacia$osm_points, bbox_st_poly)
## although coordinates are longitude/latitude, st_intersection assumes that they are planar
## Warning: attribute variables are assumed to be spatially constant throughout all
## geometries
ggplot() +
geom_sf(data = rosario_calles,
color = "darkslateblue") +
geom_sf(data = rosario_farmacia, color = "red", size=1) +
theme_void() +
labs(title = "Rosario",
subtitle = "farmacias",
caption = "fuente: OpenStreetMap")

ggplot() +
geom_sf(data = rosario_calles,
color = "darkslateblue") +
geom_sf(data = rosario_farmacia) +
geom_sf_label(data = rosario_farmacia,
aes(label = name), size = 0.5) +
theme_void() +
labs(title = "Rosario",
subtitle = "farmacias",
caption = "fuente: OpenStreetMap")
## Warning in st_point_on_surface.sfc(sf::st_zm(x)): st_point_on_surface may not
## give correct results for longitude/latitude data
## Warning: Removed 133 rows containing missing values (geom_label).

library(ggsflabel)
##
## Attaching package: 'ggsflabel'
## The following objects are masked from 'package:ggplot2':
##
## geom_sf_label, geom_sf_text, StatSfCoordinates
ggplot() +
geom_sf(data = rosario_calles,
color = "darkslateblue") +
geom_sf(data = rosario_farmacia) +
geom_sf_label_repel(data = rosario_farmacia,
aes(label = name), size = 0.5) +
theme_void() +
labs(title = "Rosario",
subtitle = "Farmacias",
caption = "fuente: OpenStreetMap")
## Warning in st_point_on_surface.sfc(data$geometry): st_point_on_surface may not
## give correct results for longitude/latitude data
## Warning: Removed 133 rows containing missing values (geom_label_repel).

Comentario: Podemos observar que la distribución de las farmacias se encuentra fuertemente sesgada al barrio centro de la ciudad y los alrededores.
b. Hacemos un conteo de las farmacias por barrio y lo mapeamos.
barrios <- st_read('https://datos.rosario.gob.ar/sites/default/files/barrios.gml')
## Reading layer `barrios' from data source `https://datos.rosario.gob.ar/sites/default/files/barrios.gml' using driver `GML'
## Simple feature collection with 50 features and 4 fields
## geometry type: POLYGON
## dimension: XY
## bbox: xmin: -60.79693 ymin: -33.03934 xmax: -60.61278 ymax: -32.86941
## CRS: 4326
rosario_farmacia
## Simple feature collection with 219 features and 30 fields
## geometry type: POINT
## dimension: XY
## bbox: xmin: -60.7776 ymin: -33.00396 xmax: -60.62281 ymax: -32.89364
## CRS: EPSG:4326
## First 10 features:
## osm_id name addr2.street addr.city addr.country
## 544689986 544689986 Lopez Temporelli <NA> <NA> <NA>
## 544689993 544689993 Solari <NA> <NA> <NA>
## 807586861 807586861 Solari <NA> <NA> <NA>
## 1981779094 1981779094 <NA> <NA> <NA> <NA>
## 1981779118 1981779118 <NA> <NA> <NA> <NA>
## 1981779122 1981779122 <NA> <NA> <NA> <NA>
## 1981779125 1981779125 <NA> <NA> <NA> <NA>
## 1981779176 1981779176 <NA> <NA> <NA> <NA>
## 1981779199 1981779199 <NA> <NA> <NA> <NA>
## 2358066357 2358066357 Bonacci <NA> <NA> <NA>
## addr.housename addr.housenumber addr.postcode
## 544689986 <NA> <NA> <NA>
## 544689993 <NA> <NA> <NA>
## 807586861 <NA> <NA> <NA>
## 1981779094 <NA> <NA> <NA>
## 1981779118 <NA> <NA> <NA>
## 1981779122 <NA> <NA> <NA>
## 1981779125 <NA> <NA> <NA>
## 1981779176 <NA> <NA> <NA>
## 1981779199 <NA> <NA> <NA>
## 2358066357 <NA> 5207 S2011
## addr.street amenity contact.phone
## 544689986 <NA> pharmacy <NA>
## 544689993 <NA> pharmacy <NA>
## 807586861 <NA> pharmacy <NA>
## 1981779094 <NA> <NA> <NA>
## 1981779118 <NA> <NA> <NA>
## 1981779122 <NA> <NA> <NA>
## 1981779125 <NA> <NA> <NA>
## 1981779176 <NA> <NA> <NA>
## 1981779199 <NA> <NA> <NA>
## 2358066357 Avenida Pedro de Castro Barros pharmacy +54 341 463-4425
## contact.website covered delivery description dispensing
## 544689986 <NA> <NA> <NA> <NA> <NA>
## 544689993 <NA> <NA> <NA> <NA> <NA>
## 807586861 <NA> <NA> <NA> <NA> <NA>
## 1981779094 <NA> <NA> <NA> <NA> <NA>
## 1981779118 <NA> <NA> <NA> <NA> <NA>
## 1981779122 <NA> <NA> <NA> <NA> <NA>
## 1981779125 <NA> <NA> <NA> <NA> <NA>
## 1981779176 <NA> <NA> <NA> <NA> <NA>
## 1981779199 <NA> <NA> <NA> <NA> <NA>
## 2358066357 <NA> <NA> <NA> <NA> <NA>
## drive_through entrance healthcare indoor level name.en name.es
## 544689986 <NA> <NA> <NA> <NA> <NA> <NA> <NA>
## 544689993 <NA> <NA> <NA> <NA> <NA> <NA> <NA>
## 807586861 <NA> <NA> <NA> <NA> <NA> <NA> <NA>
## 1981779094 <NA> <NA> <NA> <NA> <NA> <NA> <NA>
## 1981779118 <NA> <NA> <NA> <NA> <NA> <NA> <NA>
## 1981779122 <NA> <NA> <NA> <NA> <NA> <NA> <NA>
## 1981779125 <NA> <NA> <NA> <NA> <NA> <NA> <NA>
## 1981779176 <NA> <NA> <NA> <NA> <NA> <NA> <NA>
## 1981779199 <NA> <NA> <NA> <NA> <NA> <NA> <NA>
## 2358066357 <NA> <NA> <NA> <NA> <NA> <NA> <NA>
## opening_hours payment.coins phone ref.cuit shop start_date
## 544689986 <NA> <NA> <NA> <NA> <NA> <NA>
## 544689993 <NA> <NA> <NA> <NA> <NA> <NA>
## 807586861 <NA> <NA> <NA> <NA> <NA> <NA>
## 1981779094 <NA> <NA> <NA> <NA> <NA> <NA>
## 1981779118 <NA> <NA> <NA> <NA> <NA> <NA>
## 1981779122 <NA> <NA> <NA> <NA> <NA> <NA>
## 1981779125 <NA> <NA> <NA> <NA> <NA> <NA>
## 1981779176 <NA> <NA> <NA> <NA> <NA> <NA>
## 1981779199 <NA> <NA> <NA> <NA> <NA> <NA>
## 2358066357 <NA> <NA> <NA> <NA> <NA> <NA>
## wheelchair geometry
## 544689986 <NA> POINT (-60.63991 -33.00256)
## 544689993 <NA> POINT (-60.64946 -33.00225)
## 807586861 <NA> POINT (-60.64433 -32.981)
## 1981779094 <NA> POINT (-60.64216 -32.95745)
## 1981779118 <NA> POINT (-60.64223 -32.95724)
## 1981779122 <NA> POINT (-60.64195 -32.95729)
## 1981779125 <NA> POINT (-60.64214 -32.95738)
## 1981779176 <NA> POINT (-60.64198 -32.95741)
## 1981779199 <NA> POINT (-60.64228 -32.95742)
## 2358066357 <NA> POINT (-60.62986 -32.9973)
rosario_farmacia_barrios<- st_join(rosario_farmacia, barrios)
## although coordinates are longitude/latitude, st_intersects assumes that they are planar
## although coordinates are longitude/latitude, st_intersects assumes that they are planar
rosario_farmacia_barrio_2 <- rosario_farmacia_barrios %>%
group_by(BARRIO) %>%
summarise(cantidad=n())
rosario_farmacia_barrio_3<- rosario_farmacia_barrio_2 %>%
st_set_geometry(NULL)
head(rosario_farmacia_barrio_3)
## # A tibble: 6 x 2
## BARRIO cantidad
## <fct> <int>
## 1 Alberdi 1
## 2 Alberto Olmedo 1
## 3 Alvear 5
## 4 Antártida Argentina 4
## 5 Azcuenaga 4
## 6 Barrio del Abasto 26
rosario_farmacia_barrio_3 <- barrios %>%
left_join(rosario_farmacia_barrio_3, by="BARRIO")
head(rosario_farmacia_barrio_3)
## Simple feature collection with 6 features and 5 fields
## geometry type: POLYGON
## dimension: XY
## bbox: xmin: -60.72556 ymin: -32.99758 xmax: -60.6559 ymax: -32.89296
## CRS: 4326
## gml_id MSLINK BARRIO OBSERVACIO cantidad
## 1 barrios.1 28 Victoria Walsh 10 NA
## 2 barrios.2 38 14 de Octubre 10 NA
## 3 barrios.3 50 Docente "Hermanas Cossettini" 10 NA
## 4 barrios.4 22 Latinoamerica 10 NA
## 5 barrios.5 47 Bella Vista 10 NA
## 6 barrios.6 45 Parque Casado 10 6
## geometry
## 1 POLYGON ((-60.68993 -32.964...
## 2 POLYGON ((-60.66428 -32.996...
## 3 POLYGON ((-60.72556 -32.893...
## 4 POLYGON ((-60.66768 -32.968...
## 5 POLYGON ((-60.69234 -32.959...
## 6 POLYGON ((-60.66151 -32.976...
ggplot() +
geom_sf(data = rosario_farmacia_barrio_3, aes(fill=cantidad)) +
geom_sf_text(data=barrios, aes(label = BARRIO), size=1, colour = "black") +
labs(title = "Farmacias por Barrio",
fill = "Cantidad",
caption= "Fuente: https://datos.rosario.gob.ar/, OpenStreetMap",
y="",
x="") +
scale_fill_gradient(low="khaki2", high="deeppink4")
## Warning in st_point_on_surface.sfc(data$geometry): st_point_on_surface may not
## give correct results for longitude/latitude data

Comentario: Si comparamos con la distribución de hospitales con barrios (ver: https://rpubs.com/juliger/hospitales_rosario) podemos ver que la ditribución es similar, ya que existe una mayor concentración en la zona centro de la Ciudad. Vale aclarar que los hospitales no solo responden a la concentración y demógrafica y el poder adquisitivo del centro y zonas cercanas sino que también la distribución de los hospitales se corresponde con el sistema de salud público, que tiene presencia (si bien desigual) en todo el territorio.