Skip to content

Instantly share code, notes, and snippets.

@farach
Created May 18, 2019 16:11
Show Gist options
  • Select an option

  • Save farach/1e96ea364bdba0d3c286fb16bb6ecba6 to your computer and use it in GitHub Desktop.

Select an option

Save farach/1e96ea364bdba0d3c286fb16bb6ecba6 to your computer and use it in GitHub Desktop.
STEM Occupations and Wages, BLS.gov/OES data
library(tidyverse)
library(colorplaner)
library(scales)
tmp <- tempfile()
download.file("https://www.bls.gov/oes/2018/may/stem_2018.xlsx", tmp, mode = "wb")
STEM <- read_excel(tmp, sheet = "State")
STEM1 <- group_by(STEM, area_name) %>%
summarise(total_all = sum(tot_emp))
STEM2 <- select(STEM, 1:4, 7) %>%
left_join(., STEM1) %>%
filter(STEM_group == "STEM") %>%
mutate(Per_STEM = round(tot_emp/total_all, 4)) %>%
rename(state = area_name,
hourly = h_mean) %>%
select(state, Per_STEM, hourly)
state_coords <- structure(list(abbrev = c(state.abb, "PR", "VI", "GU", "DC"),
state = c(state.name, "Puerto Rico",
"Virgin Islands", "Guam",
"District of Columbia"),
col = c(8L, 1L, 3L, 6L, 2L, 4L, 11L, 11L,
10L, 9L, 1L, 3L, 7L, 7L, 6L, 5L, 7L, 6L,
12L, 10L, 11L, 8L, 6L, 7L, 6L, 4L, 5L,
3L, 12L, 10L, 4L, 10L, 8L, 5L, 8L, 5L,
2L, 9L, 12L, 9L, 5L, 7L, 5L, 3L, 11L, 9L,
2L, 8L, 7L, 4L, 12L, 12L, 1L, 10L),
row = c(7L, 1L, 6L, 6L, 5L, 5L, 4L, 5L, 8L,
7L, 7L, 3L, 3L, 4L, 4L, 6L, 5L, 7L, 1L,
5L, 3L, 3L, 3L, 7L, 5L, 3L, 5L, 4L, 2L,
4L, 6L, 3L, 6L, 3L, 4L, 7L, 4L, 4L, 4L,
6L, 4L, 6L, 8L, 5L, 2L, 5L, 3L, 5L, 2L,
4L, 8L, 7L, 8L, 6L)),
.Names = c("abbrev", "state", "x", "y"),
class = "data.frame", row.names = c(NA, -54L)) %>%
arrange(state) %>% mutate(y = -y) %>%
right_join(., STEM2)
ggplot(state_coords, aes(x, y)) +
geom_tile(aes(fill = Per_STEM), width=0.95, height=0.95) +
geom_text(aes(label = abbrev), color = "white") +
coord_fixed(ratio = 1) +
scale_x_continuous(breaks = NULL) +
scale_y_continuous(breaks = NULL) +
aes(fill2 = hourly) +
scale_fill_colorplane(labels = scales::percent(c(0.03, 0.06,
0.09),
accuracy = 1),
limits = c(0, 0.1),
breaks = c(0.03, 0.06, 0.09)) +
theme(legend.title=element_blank(),
legend.position = "right",
plot.subtitle = element_text(color = "#666666"),
plot.title = element_text(face = "bold"),
plot.caption = element_text(color = "#AAAAAA", size = 6),
panel.background = element_blank()) +
labs(title = paste("STEM Occupations and Wages"),
subtitle = "California and Washington do not have a monopoly on STEM occupations and high wages",
fill = "% of STEM Occupations",
fill2 = "Average Hourly",
x = "", y = "",
caption = paste("BLS.gov/OES,", Sys.Date()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment