HCMC Streetmap

1 Loading packages

library(tidyverse)
library(osmdata)
library(extrafont)

2 Location definition

# Area that we want to collect spatial data 
city_location <- "HCMC Vietnam"

3 OSM objects

# OSM objects that we want to get spatial 
all_street_types <- c("motorway", "primary", "secondary", "tertiary")
secondary_streets <- c("residential", "living_street", "unclassified", "service", "footway")

4 Spatial data

# Collect SPATIAL DATA for OSM objects selected: 
streets <- getbb(city_location) %>% 
  opq() %>% 
  add_osm_feature(key = "highway", value = all_street_types) %>% 
  osmdata_sf()

small_streets <- getbb(city_location) %>% 
  opq() %>% 
  add_osm_feature(key = "highway", value = secondary_streets) %>% 
  osmdata_sf()

river <- getbb(city_location) %>% 
  opq() %>% 
  add_osm_feature(key = "waterway", value = "river") %>% 
  osmdata_sf()

# LONG and LAT limits:
geo_spatial_limits <- getbb(city_location)
geo_spatial_limits
##         min       max
## x 106.54176 106.86176
## y  10.61584  10.93584

5 Color

color1 <- "cyan"
color2 <- "#ffbe7f"
back_color <- "#1d1330"
my_font <- "Georgia"

6 Streetmap - test

# Make a draft version of streetmap for HCMC
# coord_sf (..., expand = FALSE) <- error if having it 

library(ggplot2)

ggplot() +
  geom_sf(data = streets$osm_lines, inherit.aes = FALSE, color = "cyan", size = 0.4, alpha = 0.8) +
  geom_sf(data = small_streets$osm_lines, inherit.aes = FALSE, color = "#ffbe7f", size = 0.2, alpha = 0.6) +
  geom_sf(data = river$osm_lines, inherit.aes = FALSE, color = "blue", size = 1) +
  coord_sf(xlim = c(106.60, 106.75), ylim = c(10.75, 10.86), expand = FALSE, default_crs = sf::st_crs(4326)) + 
  theme(plot.background = element_rect(fill = back_color, colour = NA),
        panel.background = element_rect(fill = back_color, colour = NA), 
        axis.text = element_blank(),
        axis.ticks = element_blank(),
        axis.title = element_blank(),
        panel.grid = element_blank()) + 
  theme(plot.title = element_text(family = my_font, size = 22, color = "white")) + 
  theme(plot.margin = unit(rep(0.5, 4), "cm")) + 
  labs(title = "Streetmap of Ho Chi Minh City from Open Street Map Database")

7 Make streetmap

library(ggplot2)

ggplot() +
  geom_sf(data = streets$osm_lines, inherit.aes = FALSE, color = "cyan", size = 0.4, alpha = 0.8) +
  geom_sf(data = small_streets$osm_lines, inherit.aes = FALSE, color = "#ffbe7f", size = 0.2, alpha = 0.6) +
  geom_sf(data = river$osm_lines, inherit.aes = FALSE, color = "blue", size = 1) +
  coord_sf(xlim = c(106.60, 106.75), ylim = c(10.75, 10.86)) + 
  theme(plot.background = element_rect(fill = back_color, colour = NA),
        panel.background = element_rect(fill = back_color, colour = NA), 
        axis.text = element_blank(),
        axis.ticks = element_blank(),
        axis.title = element_blank(),
        panel.grid = element_blank()) + 
  theme(plot.title = element_text(family = my_font, size = 13, color = "white")) + 
  theme(plot.margin = unit(rep(0.5, 4), "cm")) + 
  labs(title = "Streetmap of Ho Chi Minh City from Open Street Map Database")