Created
October 8, 2024 19:51
-
-
Save cararthompson/e2b8baf12c90474307b960607310218f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rain_data <- read.csv("https://www2.sepa.org.uk/rainfall/api/Month/15201?csv=true", | |
header = T) |> | |
dplyr::mutate(city = "Edinburgh") |> | |
dplyr::bind_rows(read.csv("https://www2.sepa.org.uk/rainfall/api/Month/327234?csv=true", | |
header = T) |> | |
dplyr::mutate(city = "Glasgow")) |> | |
# Oct 2024 data is incomplete at the time of this workshop! | |
dplyr::filter(Timestamp != "Oct 2024") |> | |
tidyr::separate(Timestamp, into = c("month", "year"), remove = F) |> | |
# Make the years back into numbers | |
dplyr::mutate(year = as.numeric(as.character(year))) |> | |
# Get month factor levels in right order | |
dplyr::mutate(month = factor(month, levels = month.abb)) | |
rain_data |> | |
ggplot() + | |
geom_point(aes(x = month, | |
y = Value, | |
colour = city), | |
position = ggbeeswarm:::position_quasirandom( | |
width = 0, | |
dodge.width = 0.5)) + | |
labs(title = "Rainfall in Glasgow and Edinburgh over the years", | |
subtitle = "Each dot represents the total rainfall within a given month from 2014 to 2024.") + | |
theme_minimal(base_size = 15) + | |
scale_y_continuous(labels = function(x) paste(x, "mm")) + | |
theme(axis.title = element_blank(), | |
legend.title = element_blank()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment