forked from danielredondo/30diasdegraficos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
18_mapa.R
39 lines (32 loc) · 1.29 KB
/
18_mapa.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# Referencia: https://ggplot2tutor.com/streetmaps/streetmaps/
library(tidyverse)
library(osmdata)
# Conseguir coordenadas para ggplot
getbb("Granada, España")
# Extraer lugares del mapa
streets <- getbb("Granada, España") %>%
opq() %>%
add_osm_feature(key = "highway", value = c("motorway", "primary", "secondary", "tertiary")) %>%
osmdata_sf()
small_streets <- getbb("Granada, España") %>%
opq() %>%
add_osm_feature(key = "highway", value = c("residential", "living_street", "unclassified", "service", "footway")) %>%
osmdata_sf()
river <- getbb("Granada, España") %>%
opq() %>%
add_osm_feature(key = "waterway", value = "river") %>%
osmdata_sf()
ggplot() +
# Calles
geom_sf(data = streets$osm_lines, inherit.aes = FALSE, color = "#ffbe7f", size = .4, alpha = .8) +
# Pequeñas calles
geom_sf(data = small_streets$osm_lines, inherit.aes = FALSE, color = "#ffbe7f", size = .2, alpha = .8) +
# Ríos
geom_sf(data = river$osm_lines, inherit.aes = FALSE, color = "#7fc0ff", size = .8, alpha = .5) +
# Límites del mapa en coordenadas
coord_sf(xlim = c(-3.65, -3.55), ylim = c(37.13, 37.225), expand = FALSE) +
theme_void() +
# Añadir color de fondo
theme(plot.background = element_rect(fill = "#282828"))
# Exportación de mapa
ggsave("18.png", width = 6, height = 6)