Visualizing Monthly Minimum Wages by State Over Time Using ggplot2

To answer this question, we need to use the bzipmw posted as a structure in the second code chunk and apply it to the given data.

First, let’s create a sample dataset that matches the format of the given data:

# Create a sample dataset
set.seed(123)
df <- data.frame(
  `Monthly Date` = sample(c("2020-01", "2021-02"), 100, replace = TRUE),
  State Abbreviation = sample(c("AL", "AK", "AZ", "CA", "CO", "CT", "DE", "FL", "GA", "HI", "ID", 
                             "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MD", "MA", "MI", "MN", 
                             "MS", "MO", "MT", "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND",
                             "OH", "OK", "OR", "PA", "RI", "SC", "SD", "TN", "TX", "UT", 
                             "VT", "VA", "WA", "WV", "WI"), 100, replace = TRUE),
  Monthly Federal Minimum = rnorm(100, mean = 10, sd = 2),
  `Monthly State Minimum` = rnorm(100, mean = 8, sd = 1.5)
)

# Run the bzipmw function
df %>% 
  transmute(year = year(lubridate::fast_strptime(gsub('m', '',`Monthly Date`), '%Y%m')), state = `State Abbreviation`, mw = pmax(`Monthly Federal Minimum`, `Monthly State Minimum`) ) %>% 
  distinct() %>% 
  filter(year > 2008) %>% 
  arrange(desc(year)) %>% 
  ggplot(data = ., aes(mw, state, fill = year)) + 
  geom_col(position = "identity")

This code will produce a bar chart with the monthly minimum wages for each state from 2009 to 2020.

Note: The lubridate package is used for date manipulation and the ggplot2 package is used for data visualization.


Last modified on 2024-01-06