# Load necessary packages
pacman::p_load(pacman, tidyverse, ggrepel)
# Read the data
NHS_Organ_Donation <- read_csv("NHS_Organ_Donation.csv")
## Rows: 22 Columns: 7
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (1): Category
## dbl (6): Current year (01.04.22 - 31.03.23), Previous year (01.04.21 - 31.03...
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
# Convert the data to a tidy format for easier plotting
NHS_Organ_Donation_tidy <- NHS_Organ_Donation %>%
pivot_longer(cols = -Category, names_to = "Year", values_to = "Value")
# Filter the data for the current year and previous year
bar_data <- NHS_Organ_Donation %>%
select(Category, `Current year (01.04.22 - 31.03.23)`, `Previous year (01.04.21 - 31.03.22)`) %>%
pivot_longer(cols = -Category, names_to = "Year", values_to = "Value")
# Create the bar plot
ggplot(bar_data, aes(x = Category, y = Value, fill = Year)) +
geom_bar(stat = "identity", position = "dodge") +
labs(title = "NHS Organ Donation: Current Year vs Previous Year",
x = "Category", y = "Number of Donations") +
theme(axis.text.x = element_text(angle = 60, hjust = 1))

# Filter the data for percentage changes
scatter_data <- NHS_Organ_Donation %>%
select(Category, `% Change (Previous Year)`, `% Change (Pre-COVID Year)`) %>%
pivot_longer(cols = -Category, names_to = "Comparison", values_to = "Percentage_Change")
# Remove duplicates for scatter plot
scatter_data <- scatter_data %>%
distinct(Category, Comparison, .keep_all = TRUE)
# Create the scatter plot
ggplot(scatter_data, aes(x = Comparison, y = Percentage_Change, color = Category)) +
geom_point(size = 3) +
geom_text_repel(aes(label = Category), size = 3, max.overlaps = 78) +
labs(title = "NHS Organ Donation: Percentage Change",
x = "Comparison", y = "Percentage Change") +
theme(axis.text.x = element_text(angle = 0, hjust = 1))
