Street Maps (of Some Cities)

Some beautiful street maps

By Harshvardhan in R

May 28, 2022

Over the last few days, I dabbled with maps in R. Two days ago, I made a map of all the cities I’ve visited. Today, I thought to make street maps of some of them (and other cool cities).

The dark grey lines are highways and roadways, light grey lines are other streets and blue is water.

Jhumri Tilaiya, India

Indore, India

Riga, Latvia

Knoxville, United States

New Delhi, India

Sydney, Australia

New York, United States

Boston, United States

London, United Kingdom


The function to generate these is not complicated. For a detailed tutorial, see this tutorial. Here’s the function that I used.

library(tidyverse)
library(osmdata)

city_mapper = function(city)
{
   lts = getbb(city)
   
   streets = getbb(city)%>%
      opq()%>%
      add_osm_feature(key = "highway", 
                      value = c("motorway", "primary", 
                                "secondary", "tertiary")) %>%
      osmdata_sf()
   
   small_streets = getbb(city)%>%
      opq()%>%
      add_osm_feature(key = "highway", 
                      value = c("residential", "living_street",
                                "unclassified",
                                "service", "footway")) %>%
      osmdata_sf()
   
   river = getbb(city)%>%
      opq()%>%
      add_osm_feature(key = "waterway", value = "river") %>%
      osmdata_sf()
   
   p = ggplot() +
      geom_sf(data = streets$osm_lines,
              inherit.aes = FALSE,
              color = "#282828", #3C280D
              size = .5,
              alpha = .7) +
      geom_sf(data = small_streets$osm_lines,
              inherit.aes = FALSE,
              color = "#909090", #795C34
              size = .4,
              alpha = .4) +
      geom_sf(data = river$osm_lines,
              inherit.aes = FALSE,
              color = "#03026F",
              size = .7,
              alpha = .8) +
      coord_sf(xlim = c(lts[1], lts[3]), 
               ylim = c(lts[2], lts[4]),
               expand = FALSE) +
      theme_void() +
      labs(caption = "Learn more: harsh17.in/city-maps")
   
   return(p)
   
}
Posted on:
May 28, 2022
Length:
2 minute read, 230 words
Categories:
R
See Also: