Skip to content

Instantly share code, notes, and snippets.

@rcatlord
Last active December 4, 2023 16:41
Show Gist options
  • Save rcatlord/9fa185b4c3909b1f5cb2c8525ebe5ae4 to your computer and use it in GitHub Desktop.
Save rcatlord/9fa185b4c3909b1f5cb2c8525ebe5ae4 to your computer and use it in GitHub Desktop.
Pattern plot
# Bathing Water Classification: England
# Source: DEFRA
# URL: https://www.gov.uk/government/statistics/bathing-water-quality-statistics/2023-statistics-on-english-coastal-and-inland-bathing-waters-a-summary-of-compliance-with-the-2013-bathing-water-regulations
library(tidyverse) ; library(ggpattern)
df <- tribble(
~Classificat, ~year, ~value,
"Excelle", 2015, 63.6,
"Excelle", 2016, 69.5,
"Excelle", 2017, 65.6,
"Excelle", 2018, 67.1,
"Excelle", 2019, 71.9,
"Excelle", 2020, NA,
"Excelle", 2021, 70.7,
"Excelle", 2022, 72.1,
"Good", 2015, 26.5,
"Good", 2016, 23.7,
"Good", 2017, 26.4,
"Good", 2018, 25.2,
"Good", 2019, 21.4,
"Good", 2020, NA,
"Good", 2021, 24,
"Good", 2022, 20.8,
"Sufficie", 2015, 7,
"Sufficie", 2016, 5.3,
"Sufficie", 2017, 6.3,
"Sufficie", 2018, 5.5,
"Sufficie", 2019, 5,
"Sufficie", 2020, NA,
"Sufficie", 2021, 4.3,
"Sufficie", 2022, 4.3,
"Poor", 2015, 2.9,
"Poor", 2016, 1.5,
"Poor", 2017, 1.7,
"Poor", 2018, 2.1,
"Poor", 2019, 1.7,
"Poor", 2020, NA,
"Poor", 2021, 1,
"Poor", 2022, 2.9
) %>%
mutate(Classificat = fct_relevel(Classificat, "Excelle","Good","Sufficie","Poor"))
ggplot(df, aes(x = year, y = value), pattern = "stripe") +
geom_col_pattern(
aes(fill = Classificat, colour = Classificat, pattern_angle = Classificat),
pattern_fill = "#ffffff", pattern_color = "#ffffff", pattern_spacing = .02) +
scale_fill_manual(values = c("#3BF0F0","#16EC1B","#FCD816","#FD0200")) +
scale_colour_manual(values = c("#3BF0F0","#16EC1B","#FCD816","#FD0200")) +
scale_pattern_angle_manual(values = c(0,-45,45,90)) +
scale_x_continuous(breaks = seq(2015,2022,1)) +
labs(x = "Year",
y = "Percentage of bathing waters") +
theme_minimal() +
theme(panel.grid.minor = element_blank(),
axis.title = element_text(face = "bold"),
axis.title.x = element_text(margin = unit(c(4,0,0,0), "mm")),
axis.title.y = element_text(margin = unit(c(0,4,0,0), "mm")),
legend.title = element_text(face = "bold"))
ggsave("plot.png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment