library(tidyverse)
library(sf)
library(osmdata)
library(showtext)
Load Libraries
Set the View Point: Rome - Colosseum
Coordinates 41.8902° N, 12.4922° E
= 12.4922
long = 41.8902 lat
<- st_point(c(long, lat)) %>%
window st_sfc(crs = 4326) %>%
st_sf() %>%
st_buffer(dist = 1000) %>%
st_bbox()
window
::available_features() osmdata
Download the Buildings / Features Data for the Area of Interest:
<- opq(window) %>%
building add_osm_feature(key = "building") %>%
osmdata_sf()
<- opq(window) %>%
lanes add_osm_feature(key = "lanes") %>%
osmdata_sf()
<- opq(window) %>%
historic add_osm_feature(key = "historic") %>%
osmdata_sf()
<- building$osm_polygons
building_polygons <- lanes$osm_lines
lanes_linestrings <- historic$osm_multipolygons historic_polygons
%>%
building_polygonscount(building, sort = TRUE)
%>%
lanes_linestringscount(lanes, sort = TRUE)
%>%
historic_polygonscount(historic, sort = TRUE)
plot(historic_polygons)
<- building_polygons %>%
polygons_mod mutate(building = ifelse(!is.na(building), 'Buildings', "Other"))
Set the fonts:
font_add_google(name = 'Caveat', family = 'Caveat')
showtext_auto()
# Micromap focusing on a small neighborhood
ggplot() +
geom_sf(data = lanes_linestrings,
color = "gray") +
geom_sf(data = polygons_mod,
aes(fill = building),
linejoin = "round",
show.legend = F,
color = NA,
alpha = 0.6) +
geom_sf(data = historic_polygons,
color = "darkred",
linewidth = 0.1,
linetype = "dashed",
fill = NA,
alpha = 0.6) +
scale_fill_manual(values = c('navy','grey30')) +
coord_sf() +
labs(title = "Micromap of Buildings and Roads",
subtitle = "Rome - Historical Site\n41.8902° N, 12.4922° E",
caption = "Data: OpenStreetMap\n#30DayMapChallenge Day27 | @fgazzelloni",
x = "Longitude", y = "Latitude") +
::theme_map() +
ggthemestheme(text = element_text(family = 'Caveat', lineheight = 0.3),
plot.title = element_text(color = 'navy',
size = 80,
hjust = 0.5),
plot.subtitle = element_text(color = 'gray30',
size = 55,
hjust = 0.5),
plot.caption = element_text(color = 'gray30',
size = 50,
hjust = 0),
plot.background = element_rect(fill = 'grey90',
color = NA))
Save the map as png:
ggsave('day27_micromapping.png',
height = 8, width = 6,
dpi = 300)