Created
May 31, 2018 21:16
-
-
Save johnjosephhorton/051c5ddf5ea7a09afa3565c47f78b323 to your computer and use it in GitHub Desktop.
UC salaries by rank & dept
This file contains hidden or 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(XML) | |
library(ggplot2) | |
df <- readHTMLTable("http://projects.dailycal.org/paychecker/departments/")[[1]] | |
DeMoney <- function(x) as.numeric(gsub(",", "", gsub("\\$", "", as.character(x)))) | |
money.columns <- c("All", "Professor", "Associate professor", "Assistant professor", | |
"Lecturer") | |
for (money.column in money.columns){ | |
df[, money.column] <- sapply(df[,money.column], DeMoney) | |
} | |
df.long <- df %>% | |
dplyr::select(-Lecturer, -All) %>% | |
melt(id.vars = c("Department")) %>% | |
group_by(Department) %>% | |
mutate(overall = mean(value[variable == "Professor"], na.rm = TRUE)) | |
df.long$Department <- with(df.long, reorder(Department, overall, mean)) | |
ggplot(data = df.long %>% na.omit, aes(x = value, y = Department, shape = variable)) + | |
geom_point() + | |
scale_x_continuous(labels = scales::dollar) + | |
xlab("Annual salary") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The resulting plot is here: https://twitter.com/johnjhorton/status/1002298914354188288