This map visualizes London’s rivers and bridges using OpenStreetMap data, processed with R’s sf, osmdata, and terra packages. A smooth basemap, automated labeling, and refined aesthetics enhance clarity and readability.
Geocomputation
{osmdata}
Open Street Maps
{ggmap}
Author
Aditya Dahiya
Published
March 26, 2025
This visualization maps London’s rivers and bridges using spatial data from OpenStreetMap and background tiles from Stadia Maps. The analysis leverages sf for spatial operations, osmdata for extracting waterways and bridges, and terra for raster processing. The plot integrates a semi-transparent base map with rivers in blue and bridges in red. Labels are placed using ggrepel, and the final design is enhanced with ggtext and showtext. The result is a detailed yet aesthetic map, exported as a high-resolution PNG.
Figure 1: This map showcases London’s rivers and bridges, extracted from OpenStreetMap and overlaid on a smooth basemap. Rivers are highlighted in blue, while bridges are marked in red, with automated labels for clarity. The visualization combines spatial data processing with refined aesthetics to create an informative and visually appealing representation.
Loading required libraries, data import & creating custom functions.
Code
# Data Wrangling & Plotting Toolslibrary(tidyverse) # All things tidylibrary(sf) # Simple Features in R# Plot touch-up toolslibrary(scales) # Nice Scales for ggplot2library(fontawesome) # Icons display in ggplot2library(ggtext) # Markdown text support for ggplot2library(showtext) # Display fonts in ggplot2library(colorspace) # Lighten and Darken colours# Getting geographic data library(ggmap) # Getting raster mapslibrary(terra) # Cropping / Masking rasterslibrary(tidyterra) # Rasters with ggplot2library(osmdata) # Open Street Maps data
Visualization Parameters
Code
# Font for titlesfont_add_google("Saira",family ="title_font") # Font for the captionfont_add_google("Saira Extra Condensed",family ="caption_font") # Font for plot textfont_add_google("Saira Condensed",family ="body_font") showtext_auto()mypal <-c("red", "royalblue", "grey30", "grey10")# A base Colourbg_col <-"white"seecolor::print_color(bg_col)# Colour for highlighted texttext_hil <- mypal[3]seecolor::print_color(text_hil)# Colour for the texttext_col <- mypal[3]seecolor::print_color(text_col)# Define Base Text Sizebts <-90# Caption stuff for the plotsysfonts::font_add(family ="Font Awesome 6 Brands",regular = here::here("docs", "Font Awesome 6 Brands-Regular-400.otf"))github <-""github_username <-"aditya-dahiya"xtwitter <-""xtwitter_username <-"@adityadahiyaias"social_caption_1 <- glue::glue("<span style='font-family:\"Font Awesome 6 Brands\";'>{github};</span> <span style='color: {text_hil}'>{github_username} </span>")social_caption_2 <- glue::glue("<span style='font-family:\"Font Awesome 6 Brands\";'>{xtwitter};</span> <span style='color: {text_hil}'>{xtwitter_username}</span>")plot_caption <-paste0("**Data:** Open Street Maps & Stadia Maps", " | **Code:** ", social_caption_1, " | **Graphics:** ", social_caption_2 )rm(github, github_username, xtwitter, xtwitter_username, social_caption_1, social_caption_2)# Add text to plot-------------------------------------------------plot_title <-"London's rivers and bridges"plot_subtitle <-"This map highlights London's rivers and bridges using spatial data from OpenStreetMap, overlaid on a smooth basemap from Stadia Maps. Rivers are depicted in blue, while bridges are marked in red, with labels positioned using automated text placement techniques. The visualization integrates vector data using {sf}, extracts geographic features with {osmdata}, and processes raster backgrounds with {terra}."
# Saving a thumbnaillibrary(magick)# Saving a thumbnail for the webpageimage_read(here::here("data_vizs", "viz_london_bridges.png")) |>image_resize(geometry ="x400") |>image_write( here::here("data_vizs", "thumbnails", "viz_london_bridges.png" ) )
Session Info
Code
# Data Wrangling & Plotting Toolslibrary(tidyverse) # All things tidylibrary(sf) # Simple Features in R# Plot touch-up toolslibrary(scales) # Nice Scales for ggplot2library(fontawesome) # Icons display in ggplot2library(ggtext) # Markdown text support for ggplot2library(showtext) # Display fonts in ggplot2library(colorspace) # Lighten and Darken colours# Getting geographic data library(ggmap) # Getting raster mapslibrary(terra) # Cropping / Masking rasterslibrary(tidyterra) # Rasters with ggplot2library(osmdata) # Open Street Maps datasessioninfo::session_info()$packages |>as_tibble() |>select(package, version = loadedversion, date, source) |>arrange(package) |> janitor::clean_names(case ="title" ) |> gt::gt() |> gt::opt_interactive(use_search =TRUE ) |> gtExtras::gt_theme_espn()
Table 1: R Packages and their versions used in the creation of this page and graphics