Change in Munro Status :::
1. R code
Show code # Load the packages in ----------------------------------------------------
if ( ! require ( tidyverse ) ) {
install.packages ( "tidyverse" )
library ( tidyverse )
}
if ( ! require ( patchwork ) ) {
install.packages ( "patchwork" )
library ( patchwork )
}
if ( ! require ( ggplot2 ) ) {
install.packages ( "ggplot2" )
library ( ggplot2 )
}
if ( ! require ( ggalluvial ) ) {
install.packages ( "ggalluvial" )
library ( ggalluvial )
}
if ( ! require ( scales ) ) {
install.packages ( "scales" )
library ( scales )
}
if ( ! require ( RColorBrewer ) ) {
install.packages ( "RColorBrewer" )
library ( RColorBrewer )
}
# I stick all my styling into a CUsotm PAckage to tidy up my code and keep it consistent over the time
if ( ! require ( CustomGGPlot2Theme ) ) {
devtools :: install ( "CustomGGPlot2Theme" )
library ( CustomGGPlot2Theme )
}
scottish_munros <- readr :: read_csv (
'https://raw.githubusercontent.com/rfordatascience/tidytuesday/main/data/2025/2025-08-19/scottish_munros.csv'
)
munros_long <- scottish_munros |>
pivot_longer (
cols = `1891` : `2021` ,
names_to = "Year" ,
values_to = "Classification"
)
duplicate <- munros_long |>
filter ( ! is.na ( Classification ) ) |>
group_by ( Name ) |>
summarise ( n = n_distinct ( Classification ) ) |>
filter ( n >= 2 )
munros_clean <- munros_long |>
filter ( Name %in% duplicate $ Name ) |>
filter ( ! is.na ( Classification ) ) |>
arrange ( Name , Year ) |>
group_by ( Name , Year ) |>
slice ( 1 ) |>
ungroup ( ) |>
mutate ( Year = factor ( Year , levels = sort ( unique ( Year ) ) ) )
numbers <- munros_clean |>
group_by ( Year , Classification ) |>
summarise ( n = n ( ) , .groups = "drop" ) |>
group_by ( Year ) |>
mutate ( pct = n / sum ( n ) * 100 , y = 60 / 2 )
title = "Alluvial Plot of Scottish Munro classifications that have changed over the years"
p1 <- ggplot (
munros_clean ,
aes (
x = Year ,
stratum = Classification ,
alluvium = Name ,
fill = Classification
)
) +
geom_flow ( stat = "alluvium" ) +
geom_stratum ( ) +
geom_text (
data = numbers ,
aes (
x = Year ,
y = y ,
stratum = Classification ,
label = paste0 ( n , "\n" , round ( pct , digits = 0 ) , "%" )
) ,
stat = "stratum" ,
inherit.aes = F ,
size = 4 ,
color = "black"
) +
Custom_Style ( ) +
theme (
legend.title = element_blank ( ) ,
axis.ticks.y = element_blank ( ) ,
axis.title.y = element_text (
margin = margin ( r = 15 )
) ,
legend.key.height = unit ( 1 , "cm" ) ,
legend.key.width = unit ( 0.5 , "cm" )
) +
guides ( fill = guide_legend ( nrow = 2 ) ) +
labs ( title = str_wrap ( title , 40 ) , y = "Number of Scottish Munros" )
Back to top