EJERCICIO DE PRÁCTICA

Ciudad: Asunción, Paraguay

CONSIGNA: PARTE 1

  1. Descargar con ggmap el mapa base de la Ciudad de Asunción, Paraguay. Visualizarlo en un mapa.
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.5.2     ✔ tibble    3.3.0
## ✔ lubridate 1.9.4     ✔ tidyr     1.3.1
## ✔ purrr     1.0.4     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(sf)
## Linking to GEOS 3.12.1, GDAL 3.8.4, PROJ 9.4.0; sf_use_s2() is TRUE
library(ggmap)
## ℹ Google's Terms of Service: <https://mapsplatform.google.com>
##   Stadia Maps' Terms of Service: <https://stadiamaps.com/terms-of-service>
##   OpenStreetMap's Tile Usage Policy: <https://operations.osmfoundation.org/policies/tiles>
## ℹ Please cite ggmap if you use it! Use `citation("ggmap")` for details.
library(osmdata)
## Data (c) OpenStreetMap contributors, ODbL 1.0. https://www.openstreetmap.org/copyright
assign("has_internet_via_proxy", TRUE, environment(curl::has_internet))
bbox_asuncion <-   getbb("Asuncion, Paraguay")
mapa_base_asuncion <- get_stadiamap(bbox_asuncion, maptype = "alidade_smooth", zoom= 12)
## ℹ © Stadia Maps © Stamen Design © OpenMapTiles © OpenStreetMap contributors.
ggmap(mapa_base_asuncion)

  1. Utilizar osmdata para descargar de OpenStreetMap el polígono de la ciudad de Asunción y visualizarlo sobre el mapa base.
poligono_asuncion <- getbb("Asuncion, Paraguay",
                            format_out = "sf_polygon")
ggmap(mapa_base_asuncion)+
  geom_sf(data= poligono_asuncion, inherit.aes = FALSE)
## Coordinate system already present. Adding new coordinate system, which will
## replace the existing one.

  1. Descargar de OpenStreetMap los puntos correspondientes a “servicios financieros” (bank, atm, bureau_de_change) para la ciudad de Asunción. Visualizarlo junto al polígono y el mapa base.
financieros_asuncion <- opq(bbox_asuncion) %>% 
  add_osm_feature(key= "amenity", value = c("bank", "atm", "bureau_de_change"))
financieros_asuncion <- osmdata_sf(financieros_asuncion)
financieros_asuncion <- financieros_asuncion$osm_points
financieros_asuncion <- financieros_asuncion %>% 
  filter(!is.na(amenity))
  1. Hacer un mapa donde se les de color a los servicios financieros a partir de un atributo a elección (por ejemplo amenity). Agregar título, subtitulo y nota al pie.
ggmap(mapa_base_asuncion)+
  geom_sf(data = poligono_asuncion, inherit.aes = FALSE, fill= NA, color= "blue")+
  geom_sf(data = financieros_asuncion, inherit.aes = FALSE, aes(color= amenity))+
  labs(title = "Servicios financieros",
       subtitle = "Asunción, Paraguay",
       caption = "Fuente OpenStreetMap",
       color= "Tipo")+
  theme_void()
## Coordinate system already present. Adding new coordinate system, which will
## replace the existing one.

  1. Responder: ¿Cuántos registros hay de cada tipo de servicio financiero?
financieros_asuncion %>% 
   group_by(amenity) %>%
  summarise(cantidad=n()) %>% 
  st_drop_geometry()
## # A tibble: 3 × 2
##   amenity          cantidad
## * <chr>               <int>
## 1 atm                    65
## 2 bank                   73
## 3 bureau_de_change       16
  1. Descargar algún otro dato geográfico (a elección) de tipo línea o polígono y hacer un mapa donde se pueda ver el resultado.
caminos_asuncion <- opq(bbox_asuncion) %>% 
  add_osm_feature(key= "highway", value = c("motorway", "trunk", "primary", "secondary"))
caminos_asuncion<- osmdata_sf(caminos_asuncion)
caminos_asuncion_lines <- caminos_asuncion$osm_lines
ggmap(mapa_base_asuncion)+
  geom_sf(data = poligono_asuncion, inherit.aes = FALSE, fill= NA, color= "blue", lwd= 0.75)+
  geom_sf(data = financieros_asuncion, inherit.aes = FALSE, aes(color= amenity))+
  geom_sf(data = caminos_asuncion_lines, inherit.aes = FALSE, color= "red", lwd=0.15)
## Coordinate system already present. Adding new coordinate system, which will
## replace the existing one.

CONSIGNA: PARTE 2

  1. Realizar un mapa interactivo con los puntos descargados (servicios financieros). Agregar un color a cada tipo de servicio y un pop up que muestre el nombre y el tipo.
library(leaflet)
library(leaflet.extras)
leaflet() %>%

  addTiles() %>%

  addCircleMarkers(data=financieros_asuncion)
unique(financieros_asuncion$amenity)
## [1] "bank"             "atm"              "bureau_de_change"
pal <- colorFactor(
  palette = c("firebrick3", "dodgerblue4", "darkgreen"),
  domain = financieros_asuncion$amenity)
leaflet() %>%
  addTiles() %>%
  addCircleMarkers(
    data = financieros_asuncion,
    color = pal(financieros_asuncion$amenity),
    popup = financieros_asuncion$amenity
  ) %>%
  addLegend(
    position = "bottomright",
    pal = pal,
    values = financieros_asuncion$amenity,
    title = "Servicios financieros")
leaflet(financieros_asuncion) %>% 
  addTiles() %>% 
  addHeatmap(radius = 15,
             max = 0.05)