Catégories
R

Use data from Openstreetmap

Day 5 of 30DayMapChallenge : « Ukraine » (previously).

Using {osmdata} to extract streets :

library(dplyr)
library(ggplot2)
library(sf)
library(osmdata)
library(ggspatial)
library(glue)

ua_bbox <- getbb("kiev, ukraine", featuretype = "city")

ua <- opq(ua_bbox) %>%
  add_osm_features(features = c('"highway"="primary"',
                                '"highway"="secondary"',
                                '"highway"="tertiary"',
                                '"highway"="unclassified"',
                                '"highway"="residential"')) %>% 
  osmdata_sf()

ua$osm_lines %>% 
  bind_rows(ua$osm_multilines) %>% 
  st_set_crs("EPSG:4326") %>% 
  ggplot() +
  geom_sf(color = "#FFD700", size = 0.2) +
  annotation_scale(bar_cols =  c("#FFD700", "#0057B7"),
                   line_col = "#FFD700",
                   text_col = "#FFD700",
                   height = unit(0.1, "cm")) +
  coord_sf(xlim = ua_bbox[c(1, 3)],
           ylim = ua_bbox[c(2, 4)]) +
  labs(title = "Kyiv",
       caption = glue("© OpenStreetMap contributors
                      r.iresmi.net - {Sys.Date()}")) +
  theme_void() +
  theme(plot.background = element_rect(color = NA, 
                                       fill = "#0057B7"),
        plot.title = element_text(color = "#FFD700"),
        plot.caption = element_text(size = 5,
                                    color = "#FFD700"))

ggsave("kyiv.png", width = 20, height = 12.36, units = "cm", scale = 1.1)

Kyiv

Laisser un commentaire