library(tidyverse)
library(osmdata)
library(ggmap)
Overview
OpenStreetMap
data map for Valencia
schools and underground stations.
Resources: https://rspatialdata.github.io/osm.html
Let’s check available features, there are 263 features.
available_features()
Defining the bounding box
?getbb
<- getbb("valencia") valencia_bb
Valencia Underground
available_tags("location")
<-valencia_bb%>%
valencia opq() %>%
add_osm_feature(key = "location",value="underground") %>%
osmdata_sf()
$osm_points%>%head valencia
<- ggmap::get_map(location = "Valencia",
valencia_mapmaptype = "stamen_terrain",
zoom=13)
ggmap(valencia_map) +
geom_sf(
data = valencia$osm_polygons,
inherit.aes = FALSE,
colour = "#cc161d",
fill = "#be2d42",
size = 2
+
) geom_sf(
data = valencia$osm_points,
inherit.aes = FALSE,
colour = "#cc161d",
fill = "#be2d42",
size = 0.2
+
) labs(x = "", y = "")
Vlencia Schools
::available_tags("amenity") osmdata
<-
valencia_schools %>%
valencia_bbopq() %>%
add_osm_feature(key="amenity",value="school")%>%
osmdata_sf()
<- ggmap::get_map(location = "Valencia",
valencia_map2maptype = "stamen_terrain_lines",
zoom=13)
ggmap(valencia_map2) +
geom_sf(
data = valencia$osm_polygons,
inherit.aes = FALSE,
colour = "#cc161d",
fill = "#be2d42",
size = 2
+
) geom_sf(
data = valencia$osm_points,
inherit.aes = FALSE,
colour = "#cc161d",
size = 0.2
+
) geom_sf(
data = valencia_schools$osm_polygons,
inherit.aes = FALSE,
fill = "#40E0D0",color="#A0522D",
size = 0.2
+
) labs(title="València")+
::theme_map(base_size = 14,base_family = "Gill Sans") ggthemes
<- valencia_bb %>%
valencia_streets opq() %>%
add_osm_feature("highway", c("motorway", "primary", "secondary", "tertiary")) %>%
osmdata_sf()
# retrieving data of small streets in Lagos
<- valencia_bb %>%
valencia_small_streets opq() %>%
add_osm_feature(key = "highway", value = c("residential", "living_street", "unclassified", "service", "footway")) %>%
osmdata_sf()
# retrieving data of rivers in Lagos
<- valencia_bb %>%
valencia_rivers opq() %>%
add_osm_feature(key = "waterway", value = "river") %>%
osmdata_sf()
ggmap(valencia_map2)+
geom_sf(data = valencia_streets$osm_lines,
inherit.aes = FALSE,
color = "#ffbe7f", linewidth = .2, alpha = .8) +
geom_sf(data = valencia_small_streets$osm_lines,
inherit.aes = FALSE,
color = "#a6a6a6", linewidth = .01, alpha = .8) +
geom_sf(data = valencia_rivers$osm_lines,
inherit.aes = FALSE,
color = "#7fc0ff", size = .8, alpha = .5)+
geom_sf(
data = valencia$osm_polygons,
inherit.aes = FALSE,
colour = "#cc161d",
fill = "#be2d42",
size = 2
+
) geom_sf(
data = valencia$osm_points,
inherit.aes = FALSE,
aes(colour = "#cc161d"),
size = 0.2
+
) geom_sf(
data = valencia_schools$osm_polygons,
inherit.aes = FALSE,
aes(fill = "#40E0D0",color="#A0522D"),
size = 0.2,key_glyph = draw_key_pointrange
+
) geom_sf(
data = valencia_schools$osm_polygons,
inherit.aes = FALSE,
color="#A0522D",fill=NA,
size = 0.2,
+
) scale_color_manual(values=c("#40E0D0","#cc161d"),labels=c("Schools","Underground"))+
scale_fill_manual(values=c("#40E0D0"))+
guides(fill="none",
color=guide_legend(title.position ="left"))+
coord_sf(clip="off")+
labs(title="València, ES",
subtitle="#30DayMapChallenge2023 Day 15 - OpenStreetMap",
caption="DataSource: {osmdata} | Map: @fgazzelloni",
color="")+
::theme_map(base_size = 14,base_family = "Gill Sans")+
ggthemestheme(plot.title = element_text(hjust = 0.5,size=20),
plot.subtitle = element_text(size=10,hjust = 0.5),
plot.title.position = "plot",
legend.box.background = element_blank(),
#legend.background = element_blank(),
legend.position = c(0.8,0.05))+
::annotation_scale(hjust=1) ggspatial
ggsave("day15_openstreetmap.png",
scale = 0.5,
limitsize=F,
bg="#f0f0f0")