MIDN Rylie Cottrill SD322 Week 5 Assignment.
Level B.
library(tidyverse)
df_2022 <- read_csv(“2022_layoffs.csv”) %>% mutate(year = “2022”) df_2023 <- read_csv(“2023_layoffs.csv”) %>% mutate(year = “2023”) df_2024 <- read_csv(“2024_layoffs.csv”) %>% mutate(year = “2024”)
layoffs_all <- bind_rows(df_2022, df_2023, df_2024) %>% mutate(year = as.factor(year), known_count = !is.na(Headcount))
label_threshold <- 500 top_layoffs <- layoffs_all %>% filter(known_count, Headcount >= label_threshold)
totals_per_year <- layoffs_all %>% group_by(year) %>% summarize(total_headcount = sum(Headcount, na.rm = TRUE))
year_colors <- c( “2022” = “#FEE08B”,
“2023” = “#FC8D59”,
“2024” = “#D73027” )
myrecreation <- ggplot() +
geom_jitter( data = layoffs_all %>% filter(!known_count), aes(x = year, y = 0.5, shape = “Unknown”), fill = “gray70”, # Making the bubbles gray with pre-existing R color. size = 3, # Making them small by default because the count is unknown. width = 0.4, height = 0.2, show.legend = TRUE # Showing the legend. ) +
geom_jitter( data = layoffs_all %>% filter(known_count), aes(x = year, y = 0.5, size = Headcount, fill = year), shape = 21, alpha = 0.8, # Making the bubbles slightly transparent so every point can still be seen even if they overlap. width = 0.4, height = 0.2, show.legend = FALSE # Legend not needed for these. ) +
geom_text( data = totals_per_year, aes(x = year, y = 0.02, label = total_headcount, color = year), size = 3 ) +
geom_text( data = top_layoffs, aes(x = year, y = 0.5, label =
Studio), size = 3, fontface = “bold”, # Making them easier to read.
position = position_jitter(width = 0.4, height = 0.2), # Giving the
labels the same offset as the bubbles. check_overlap = TRUE
# This setting was really helpful for making my recreation actually
readable. It eliminates overlapping labels. Referenced https://ggplot2.tidyverse.org/reference/geom_text.html.
) +
scale_size(range = c(1, 25)) + # Smallest circles will be size 1 and biggest will be size 25. scale_fill_manual(values = year_colors) + scale_color_manual(values = year_colors) + # Color coding the layoff totals. scale_shape_manual(name = ““, values = 21) + # Keeping the unknown count legend. guides(fill =”none”, color = “none”, size = “none”) + # Removing all other legends.
theme_minimal() + theme( panel.grid = element_blank(), # Removed grid to make it look cleaner. axis.text.y = element_blank(), axis.title.y = element_blank(), # Removing unnecessary elements on the y axis. text = element_text(family = “Times New Roman”), plot.title = element_text(face = “bold”, size = 18), # Making the title look more accurate to the original. plot.subtitle = element_text(size = 14), legend.position = c(0.05, 0.05), # Moving the Unknown legend to the bottom left. legend.text = element_text(size = 10) ) +
labs( title = “Games Industry Layoffs”, subtitle = “January 2022 to December 2024”, x = “Year” )
myrecreation