library(tidyverse)
library(fuzzyjoin)
library(ggthemes)
library(ggridges)
library(flextable)
library(janitor)
library(stringi)
library(tidytext)
library(sf)
library(plotly)
library(rnaturalearth)
# read in the walkhighlands data
walkhighlands <- read_csv("walkhighlands_corbetts.csv") |>
rename("name" = "corbett")
# read in the dobih and just select the columns i need and rename some stuff
raw_data <- read_csv("https://www.hills-database.co.uk/corbettab_v4.csv")
scottish_corbetts <- raw_data |>
filter(`Post 1997` == "CORBETT") |>
select(
`DoBIH Number`, Name,
`Height (m)`, xcoord, ycoord, "Grid Ref",
) |>
drop_na(`DoBIH Number`) |>
rename(
name = "Name",
height = `Height (m)`,
number = `DoBIH Number`,
grid_ref = "Grid Ref"
)
rm(raw_data)
# rename some of the Corbets to facilitate the join
scottish_corbetts <- scottish_corbetts %>%
mutate(corbett = case_when(
name == "Stob a'Choin" ~ "Stob a' Choin",
name == "Beinn Stacach [Ceann na Baintighearna] [Stob Fear-tomhais] [Beinn Stacath]" ~ "Beinn Stacath",
name == "Beinn a'Choin" ~ "Beinn a' Choin",
name == "Stob Coire Creagach [Binnein an Fhidhleir]" ~ "Binnein an Fhìdhleir (or Stob Coire Creagach)",
name == "Sron a'Choire Chnapanich [Sron a'Choire Chnapanaich]" ~ "Sron a' Choire Chnapanich",
name == "Beinn a'Chaisteil" & height == 886 ~ "Beinn a' Chaisteil (Auch)",
name == "Beinn a'Chaisteil" & height == 787 ~ "Beinn a' Chaisteil (Strath Vaich)",
name == "Beinn a'Chrulaiste" ~ "Beinn a' Chrùlaiste",
name == "Beinn a'Bhuiridh" ~ "Beinn a' Bhuiridh",
name == "Beinn a'Chuallaich" ~ "Beinn a' Chuallaich",
name == "A'Chaoirnich [Maol Creag an Loch]" ~ "Maol Creag an Loch (A' Chaoirnich)",
name == "Meall a'Bhuachaille" ~ "Meall a' Bhuachaille",
name == "Carn a'Chuilinn" ~ "Càrn a' Chuilinn",
name == "Sgorr Craobh a'Chaorainn" ~ "Sgòrr Craobh a' Chaorainn",
name == "Stob Coire a'Chearcaill" ~ "Stob Coire a' Chearcaill",
name == "Druim nan Cnamh [Beinn Loinne]" ~ "Beinn Loinne",
name == "Sgurr a'Choire-bheithe" ~ "Sgùrr a' Choire-bheithe",
name == "Bidein a'Chabair" ~ "Bidein a' Chabair",
name == "Meall a'Phubuill" ~ "Meall a' Phùbuill",
name == "Carn a'Choire Ghairbh" ~ "Càrn a' Choire Ghairbh",
name == "Sgurr a'Mhuilinn" ~ "Sgùrr a' Mhuilinn",
name == "Beinn a'Bha'ach Ard [Beinn a'Bhathaich Ard]" ~ "Beinn a' Bha'ach Ard",
name == "Meall a'Ghiubhais [Meall a'Ghiuthais]" ~ "Meall a' Ghiubhais",
name == "Sgurr a'Chaorachain" ~ "Sgùrr a' Chaorachain",
name == "Beinn a'Chlaidheimh" ~ "Beinn a' Chlaidheimh",
name == "Beinn a'Chaisgein Mor" ~ "Beinn a' Chaisgein Mòr",
name == "Beinn Liath Mhor a'Ghiubhais Li [Beinn Liath Mhor a'Ghiuthais]" ~ "Beinn Liath Mhòr a' Ghiubhais Li",
name == "Foinaven [Foinne Bhein] - Ganu Mor" ~ "Foinaven",
name == "Ben Loyal - An Caisteal" ~ "Ben Loyal",
name == "Quinag - Sail Gorm [Sail Ghorm]" ~ "Quinag - Sàil Ghorm",
name == "Glamaig - Sgurr Mhairi" ~ "Glamaig",
name == "Goatfell [Goat Fell]" ~ "Goat Fell",
name == "An Cliseam [Clisham]" ~ "Clisham",
name == "Carn Dearg" & height == 817 ~ "Càrn Dearg North Eachach",
name == "Carn Dearg" & height == 768 ~ "Càrn Dearg South Eachach",
name == "Carn Dearg" & height == 834 ~ "Càrn Dearg - Glen Roy",
name == "The Cobbler [Ben Arthur]" ~ "The Cobbler",
name == "The Sow of Atholl [Meall an Dobharchain]" ~ "The Sow of Atholl",
name == "Druim Tarsuinn [Stob a'Bhealach an Sgriodain]" ~ "Druim Tarsuinn",
name == "Ben Aden [Beinn an Aodainn]" ~ "Ben Aden",
name == "Beinn Pharlagain [Ben Pharlagain - Meall na Meoig]" ~ "Beinn Pharlagain",
TRUE ~ name
))
walkhighlands <- walkhighlands |>
mutate(name = case_when(name == "Càrn Dearg (North of Gleann Eachach)" ~ "Càrn Dearg North Eachach",
name == "Càrn Dearg (South of Gleann Eachach)" ~ "Càrn Dearg South Eachach",
TRUE ~ name))
# Normalise names for join
walkhighlands <- walkhighlands %>%
mutate(
corbett_key = name %>%
str_replace_all("\\s*\\([^)]*\\)", "") %>%
stri_trans_general("Latin-ASCII") %>%
str_to_lower() %>%
str_squish(),
height = as.numeric(height)
)
scottish_corbetts <- scottish_corbetts %>%
mutate(
corbett_key = corbett %>%
str_replace_all("\\s*\\([^)]*\\)", "") %>%
stri_trans_general("Latin-ASCII") %>%
str_to_lower() %>%
str_squish(),
height = as.numeric(height)
)
# --- Fuzzy INNER JOIN (only matches kept) ---
tol_m <- 10
corbett_dat <- fuzzy_inner_join(
walkhighlands,
scottish_corbetts,
by = c("corbett_key" = "corbett_key", "height" = "height"),
match_fun = list(`==`, function(a, b) abs(a - b) <= tol_m)
) %>%
rename_with(~ str_replace(.x, "\\.x$", "_wh")) %>%
rename_with(~ str_replace(.x, "\\.y$", "_dobih")) %>%
mutate(height_diff = abs(height_wh - height_dobih),
time = (time_hours_min +time_hours_max)/2,
type = "corbett") |>
select(type, "name" = "name_wh",
region,
height_wh, height_dobih, height_diff, time,
first_route_title,, everything(), -name_dobih, -corbett_key_wh, -corbett_key_dobih, -corbett)|>
mutate(scramble_exposed = case_when(
scramble & exposed ~ "Both",
scramble & !exposed ~ "Scramble",
!scramble & exposed ~ "Exposed",
TRUE ~ "Neither"
)) |>
mutate(scramble_exposed = factor(scramble_exposed,
levels = c("Neither", "Scramble", "Exposed", "Both"))) |>
mutate(wet = case_when(
spate & bog ~ "Both",
spate & !bog ~ "Large river",
!spate & bog ~ "Boggy",
TRUE ~ "Neither"
)) |>
mutate(wet = factor(wet,
levels = c("Neither", "Large river", "Boggy", "Both")))
# make some colour palettes
nature_6 <- c(
"#355E3B",
"#4B4F58",
"#4682B4",
"#8E6C88",
"#E07B39",
"#BDB76B"
)
nature_5 <- c(
"#355E3B",
"#4B4F58",
"#4682B4",
"#E07B39",
"#BDB76B"
)
nature_4 <- c(
"#355E3B",
"#4B4F58",
"#4682B4",
"#E07B39"
)
nature_2 <- c(
"#355E3B",
"#4682B4"
)
nature_13 <- c(
"#355E3B", # Pine green
"#6B8E23", # Moss
"#BDB76B", # Dry grass
"#8B5A2B", # Earth brown
"#D2B48C", # Sand
"#87CEEB", # Sky blue
"#4682B4", # Loch blue
"#191970", # Mountain shadow (midnight blue)
"#7D7D7D", # Granite grey
"#A9A9A9", # Slate grey
"#8E6C88", # Heather purple
"#E07B39", # Sunset orange
"#FFD700" # Sun yellow
)
nature_11 <- c(
"#355E3B", # Pine green
"#6B8E23", # Moss
"#8B5A2B", # Earth brown
"#D2B48C", # Sand
"#87CEEB", # Sky blue
"#4682B4", # Loch blue
"#7D7D7D", # Granite grey
"#A9A9A9", # Slate grey
"#8E6C88", # Heather purple
"#E07B39", # Sunset orange
"#FFD700" # Sun yellow
)
nature_19 <- c(
"#355E3B", # Pine green
"#6B8E23", # Moss
"#BDB76B", # Dry grass
"#8B5A2B", # Earth brown
"#D2B48C", # Sand
"#87CEEB", # Sky blue
"#4682B4", # Loch blue
"#191970", # Mountain shadow (midnight blue)
"#7D7D7D", # Granite grey
"#A9A9A9", # Slate grey
"#8E6C88", # Heather purple
"#E07B39", # Sunset orange
"#FFD700", # Sun yellow
"#228B22", # Forest green
"#B22222", # Red clay / bracken
"#FF69B4", # Wildflower pink
"#40E0D0", # Turquoise (river shallows)
"#C0C0C0", # Silver mist
"#800080" # Deep purple (moorland heather)
)
# create route data
route_dat <-corbett_dat |>
select(first_route_url, first_route_title,
region, time_hours_min:deer_fence, time, scramble_exposed, wet, type) |>
unique()
route_stats <- corbett_dat |>
group_by(first_route_title) |>
summarise(route_rating = janitor::round_half_up(mean(rating), 2),
route_ascents = janitor::round_half_up(mean(ascents),0 ))
route_dat <- route_dat |>
left_join(route_stats)
rm(route_stats)
## load in munro dat and combine it
munro_dat <- read_csv("munros_combined.csv")|>
mutate(type = "munro",
ycoord = as.character(ycoord))|>
rename("name" = "munro")
combined_dat <- bind_rows(corbett_dat, munro_dat)|>
mutate(scramble_exposed = factor(scramble_exposed,
levels = c("Neither",
"Scramble",
"Exposed",
"Both")))
route_dat_combined <-combined_dat |>
select(first_route_url, first_route_title,
region, time_hours_min:deer_fence, time, scramble_exposed, wet, type) |>
unique()
route_stats_combined <- combined_dat |>
group_by(first_route_title) |>
summarise(route_rating = janitor::round_half_up(mean(rating), 2),
route_ascents = janitor::round_half_up(mean(ascents),0 ))
route_dat_combined <- route_dat_combined |>
left_join(route_stats_combined)
rm(munro_dat, route_stats_combined, walkhighlands)