Last active
July 8, 2024 14:17
-
-
Save farach/a63bbd9b95b4277103632bf418171e35 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
library(fredr) | |
library(tidyverse) | |
library(geofacet) | |
library(ggrepel) | |
library(ggtext) | |
set.seed(42) # For reproducibility | |
# Prepare state series IDs | |
state_ids <- c( | |
map_chr(state.abb, ~ paste0("STTMINWG", .x)), | |
"STTMINWGDC" | |
) %>% | |
setdiff(c( | |
"STTMINWGAL", "STTMINWGLA", | |
"STTMINWGMS", "STTMINWGSC", | |
"STTMINWGTN" | |
)) | |
# Fetch minimum wage data for each state | |
min_wage <- map_dfr( | |
state_ids, | |
~ fredr( | |
series_id = .x, | |
observation_start = as.Date("2000-01-01"), | |
observation_end = Sys.Date() | |
) %>% | |
mutate(st = str_sub(.x, -2)) | |
) | |
# Fetch federal minimum wage data | |
fed_mw <- fredr( | |
series_id = "FEDMINNFRWG", | |
observation_start = as.Date("2000-01-01"), | |
observation_end = Sys.Date() | |
) %>% | |
mutate(st = "FED") | |
# Combine state and federal minimum wage data | |
min_wage_full <- min_wage %>% | |
full_join( | |
expand_grid( | |
st = state.abb, | |
date = seq.Date(as.Date("2000-01-01"), Sys.Date(), by = "year") | |
), | |
by = c("st", "date") | |
) %>% | |
left_join( | |
fed_mw %>% | |
select(date, value_fed = value), | |
by = "date" | |
) %>% | |
mutate(value = coalesce(value, value_fed)) %>% | |
select(date, st, value, value_fed) %>% | |
arrange(st, date) | |
# Prepare data for area step plot | |
min_wage_area_step <- min_wage_full %>% | |
transmute( | |
date, st, value, | |
source = "new" | |
) %>% | |
bind_rows( | |
min_wage_full %>% | |
transmute( | |
date, st, | |
value = lag(value), | |
source = "old" | |
) | |
) %>% | |
arrange(date, st, source) | |
# Plotting | |
min_wage_full %>% | |
ggplot(aes(date, value)) + | |
geom_ribbon( | |
aes(x = date, ymin = 0, ymax = value), | |
alpha = 0.6, | |
fill = "#460073", | |
data = min_wage_area_step | |
) + | |
geom_step(aes(date, value_fed), color = "black", linetype = "dashed") + | |
labs( | |
x = "Year", | |
y = "Min Wage", | |
title = "USA State Minimum Wage over Time", | |
caption = "Source:\nfred.stlouisfed.org\ndol.gov/agencies/whd/minimum-wage" | |
) + | |
geom_text_repel( | |
aes(label = text), | |
size = 3.5, | |
hjust = .5, | |
min.segment.length = 0, | |
nudge_y = 5, | |
data = tibble( | |
date = as.Date("2016-01-01"), | |
value = 7.25, | |
st = factor("WI", levels = state.abb), | |
text = "Fed Min\nWage" | |
) | |
) + | |
facet_geo(~ st) + | |
scale_x_date(date_labels = "'%y") + | |
scale_y_continuous(labels = scales::dollar) + | |
coord_cartesian(clip = "off") + | |
theme_minimal() + | |
theme( | |
panel.grid.minor = element_blank(), | |
axis.ticks = element_blank(), | |
plot.title = element_markdown( | |
face = "bold", | |
size = 20, | |
hjust = 0.5 | |
), | |
plot.title.position = "plot", | |
plot.subtitle = element_markdown( | |
size = 14, | |
hjust = 0 | |
), | |
plot.caption = element_markdown( | |
size = 9, | |
hjust = 1, | |
margin = margin(t = 15) | |
), | |
plot.caption.position = "plot", | |
axis.title = element_markdown( | |
size = 10, | |
), | |
axis.text = element_text( | |
size = 9, | |
), | |
axis.text.x = element_text( | |
margin = margin(5, b = 10) | |
), | |
axis.title.y = element_text( | |
margin = margin(r = 20) | |
), | |
plot.margin = margin(25, 25, 10, 25) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment