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
![](/city-maps/index_files/figure-html/unnamed-chunk-2-1.png)
Indore, India
![](/city-maps/index_files/figure-html/unnamed-chunk-3-1.png)
Riga, Latvia
![](/city-maps/index_files/figure-html/unnamed-chunk-4-1.png)
Knoxville, United States
![](/city-maps/index_files/figure-html/unnamed-chunk-5-1.png)
New Delhi, India
![](/city-maps/index_files/figure-html/unnamed-chunk-6-1.png)
Sydney, Australia
![](/city-maps/index_files/figure-html/unnamed-chunk-7-1.png)
New York, United States
![](/city-maps/index_files/figure-html/unnamed-chunk-8-1.png)
Boston, United States
![](/city-maps/index_files/figure-html/unnamed-chunk-9-1.png)
London, United Kingdom
![](/city-maps/index_files/figure-html/unnamed-chunk-10-1.png)
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)
}