Forked from johnjosephhorton/uc_salaries_by_dept_and_rank.R
Created
June 1, 2018 01:24
-
-
Save kjhealy/02648bcc702184614fada0daafbf8299 to your computer and use it in GitHub Desktop.
UC salaries by rank & dept
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(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