map
geography
Published

August 17, 2025

Code
#### TIDY TUESDAY 2025 
#### 2025-08-17 - SCOTTISH MUNROS 

#---------- 1. SETUP

library(pacman)

pacman::p_load(tidyverse, ggtext, showtext, sf, ggrepel, grid,
               rnaturalearth, rnaturalearthdata, geosphere)
               
               
scottish_munros <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/main/data/2025/2025-08-19/scottish_munros.csv') %>% 
  filter(!is.na(xcoord), !is.na(ycoord)) %>%
  mutate(
    # Was it a Munro in 2021?
    munro2021 = (`2021` == "Munro"),
    
    # Was it a Munro in any *other* year?
    munro_other = apply(select(., all_of(year_cols[-length(year_cols)])), 1, function(row) {
      any(row == "Munro", na.rm = TRUE)
    }),
    
    # "One-time Munros": Munro in 2021 and never before
    one_time_2021 = munro2021 & !munro_other
  )

#---------- 2. DATA WRANGLING 

# create shapefile 

munros_sf <- st_as_sf(scottish_munros, coords = c("xcoord", "ycoord"), crs = 27700)

# scotland outline 

scotland <- ne_countries(country = "United Kingdom", scale = "medium", returnclass = "sf") %>%
  filter(sovereignt == "United Kingdom")

scotland <- st_transform(scotland, 27700)

# highest munro 

highest <- munros_sf %>%
  filter(Height_m == max(Height_m, na.rm = TRUE))

# most remote munro (from other munros)

coords <- st_coordinates(munros_sf)

dist_matrix <- st_distance(munros_sf, munros_sf)

dist_matrix <- units::drop_units(dist_matrix)

nearest_dist <- apply(dist_matrix, 1, function(x) min(x[x > 0]))

munros_sf$nearest_dist <- nearest_dist

remote <- munros_sf %>%
  filter(nearest_dist == max(nearest_dist, na.rm = TRUE))

# became munro in 2021 
year_cols <- c("1891","1921","1933","1953","1969","1974","1981","1984","1990","1997","2021")

unique_2021_only <- munros_sf %>% filter(one_time_2021)

#---------- 3. PLOT

font_add_google("IM Fell English", "fell")
font_add_google("Didact Gothic", "gothic")
showtext_auto()

ggplot() +
  # Scotland outline
  geom_sf(data = scotland, fill = "antiquewhite1", color = "grey30") +
  # All Munros as grey triangles
  geom_sf(data = munros_sf, shape = 24, fill = "grey40", color = "black", size = 1.5, alpha = 0.5) +
  # Newest
  geom_sf(data = unique_2021_only, shape = 24, size = 4, fill = "darkgreen", color = "black") +
  
  # Highest (Ben Nevis) – red triangle
  geom_sf(data = highest, shape = 24, size = 4, fill = "darkred", color = "black") +
  
  # Most remote (Ben More) – navy triangle
  geom_sf(data = remote, shape = 24, size = 4, fill = "navy", color = "black") +
  
  # Zoom to Scotland only
  coord_sf(xlim = c(st_bbox(munros_sf)$xmin - 20000, st_bbox(munros_sf)$xmax + 20000), 
           ylim = c(st_bbox(munros_sf)$ymin - 20000, st_bbox(munros_sf)$ymax + 20000)) +
  theme_void(base_family = "fell") +
  theme(
    panel.background = element_rect(fill = "antiquewhite", color = NA),
    plot.background = element_rect(fill = "antiquewhite", color = NA),
    plot.title = element_text(family = "fell", face = "bold", size = 24, hjust = 0.5),
    plot.subtitle = element_markdown(family = "gothic", size = 14, hjust = 0.5, lineheight = 1.1),
    plot.caption = element_text(family = "fell", size = 10, hjust = 1),
    plot.margin = margin(20, 20, 20, 20) 
  ) +
  labs(
    title = "The Munros of Scotland",
    subtitle = "A Munro is a Scottish mountain above 3000 feet<br>
<span style='color:darkred; font-weight:bold;'>Ben Nevis</span> is the highest, <span style='color:navy; font-weight:bold;'>Ben More</span> the most remote<br>
and <span style='color:darkgreen; font-weight:bold;'>Beinn a' Chroin</span> the most recent addition",
    caption = "Data: DoBIH | TidyTuesday | @anabodevan"
  )