Instalar y activar paquetes necesarios.
##
#install.packages("tidyverse")
#install.packages("osmdata")
#install.packages("plotly")
#install.packages("sf")
##
library(tidyverse)
## -- Attaching packages -------------------------------------------------------------------------------- tidyverse 1.3.0 --
## v ggplot2 3.2.1 v purrr 0.3.3
## v tibble 2.1.3 v dplyr 0.8.3
## v tidyr 1.0.0 v stringr 1.4.0
## v readr 1.3.1 v forcats 0.4.0
## -- Conflicts ----------------------------------------------------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(osmdata)
## Data (c) OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(sf)
## Linking to GEOS 3.6.1, GDAL 2.2.3, PROJ 4.9.3
Buscar las coordenadas de la ciudad, en este caso Buenos Aires.
getbb("buenos aires")
## min max
## x -58.53145 -58.33512
## y -34.70564 -34.52655
Crear los objetos que contengan las calles, avenidas, etc.
streets <- getbb("Buenos Aires")%>%
opq()%>%
add_osm_feature(key = "highway",
value = c("motorway", "primary", "secondary", "tertiary")) %>%
osmdata_sf()
small_streets <- getbb("Buenos Aires")%>%
opq()%>%
add_osm_feature(key = "highway",
value = c("residential", "living_street","unclassified","service", "footway")) %>%
osmdata_sf()
river <- getbb("Buenos Aires")%>%
opq()%>%
add_osm_feature(key = "waterway", value = "river") %>%
osmdata_sf()
trains <- getbb("Buenos Aires")%>%
opq()%>%
add_osm_feature(key = "railway",
value = c("rail", "subway","light_rail")) %>%
osmdata_sf()
Para calles chicas, secundarias, avenidas, trenes y subtes:
ggplot() +
geom_sf(data = streets$osm_lines,
inherit.aes = FALSE,
color = "#7fc0ff", size = .6,
alpha = .8) +
geom_sf(data = small_streets$osm_lines,
inherit.aes = FALSE,
color = "#ffbe7f", size = .1,
alpha = .6) +
geom_sf(data = river$osm_lines,
inherit.aes = FALSE,
color = "#ffbe7f", size = .2,
alpha = .5) +
geom_sf(data = trains$osm_lines,
inherit.aes = FALSE,
color = "#770da1", size = .7, alpha = .5) +
coord_sf(xlim = c(-58.53145, -58.33512),
ylim = c(-34.70564, -34.52655),
expand = FALSE) +
theme_void() +
theme( plot.background = element_rect(fill = "#282828") )
Para trenes y avenidas:
ggplot() +
geom_sf(data = streets$osm_lines,
inherit.aes = FALSE,
color = "#7fc0ff", size = .6,
alpha = .8) +
geom_sf(data = trains$osm_lines,
inherit.aes = FALSE,
color = "#770da1", size = .7,
alpha = .5) +
coord_sf(xlim = c(-58.53145, -58.33512),
ylim = c(-34.70564, -34.52655),
expand = FALSE) +
theme_void() +
theme( plot.background = element_rect(fill = "#282828") )