MIDN Rylie Cottrill SD322 Week 5 Assignment.

Level B.

library(tidyverse)

First I am loading the data from csv’s given on the website and assigning them to years in a separate column because the original date column was hard to use.

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”)

Next I am combining all the years and flagging the known vs unknown counts so I can color code them later.

layoffs_all <- bind_rows(df_2022, df_2023, df_2024) %>% mutate(year = as.factor(year), known_count = !is.na(Headcount))

In the original graphic, the largest bubbles are labeled. To recreate this, I decided to create a threshold for layoff count to distinguish which larger bubbles to label. I chose 500 because it seemed to display similar companies to the original.

label_threshold <- 500 top_layoffs <- layoffs_all %>% filter(known_count, Headcount >= label_threshold)

There are also total layoffs per year at the bottom of the graphic so I calculated those here.

totals_per_year <- layoffs_all %>% group_by(year) %>% summarize(total_headcount = sum(Headcount, na.rm = TRUE))

The original graphic color coded the bubbles by year. I found a similar yellow, orange, and red and used those colors in hex. Referenced https://r-graph-gallery.com/ggplot2-color.html.

year_colors <- c( “2022” = “#FEE08B”,
“2023” = “#FC8D59”,
“2024” = “#D73027” )

Next I worked on creating the plot. The first few times I tried to create my graphic, all the bubbles I tried to plot were crowded on top of each other and looked very messy. I used geom_jitter to spread them and make it look more similar to the original. Referenced https://ggplot2.tidyverse.org/reference/geom_jitter.html.

myrecreation <- ggplot() +

First I am handling all my unknown layoff count bubbles.

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. ) +

Now I am handling the known layoff counts that are color coded by year.

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. ) +

Next I added the labels for total layoffs per year. In the original graphic, they were color coded to match the year so I will do that later as well.

geom_text( data = totals_per_year, aes(x = year, y = 0.02, label = total_headcount, color = year), size = 3 ) +

Now I am using the top layoffs I found earlier and labeling them.

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. ) +

Next I worked on scaling the bubbles so they reflected the size of the layoff count at that company. Referenced https://ggplot2.tidyverse.org/reference/scale_manual.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.

Next I used theme() to tweak the looks of my graphic to make it look more accurate to the original. Referenced https://ggplot2.tidyverse.org/reference/theme.html.

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) ) +

Adding the actual title labels to my graphic.

labs( title = “Games Industry Layoffs”, subtitle = “January 2022 to December 2024”, x = “Year” )

myrecreation