Last active
August 29, 2015 14:22
-
-
Save jsonbecker/10a7210a10292b208d91 to your computer and use it in GitHub Desktop.
providencefirefighters.R
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
install.packages('rvest') | |
library(rvest) | |
library(dplyr) | |
page <- html('http://app.providencejournal.com/topics/special-reports/tables/firefigher-salaries-fy2014/firefighter-salaries.htm') | |
data <- page %>% | |
html_node('table') %>% | |
html_table() %>% | |
.[c(-1,-2,-3),] %>% | |
as.data.frame | |
data <- as.data.frame(apply(data, 2, function(x) gsub('\\$', '', x))) | |
data[, c('Listed Salary', 'Base pay', 'Longevity', | |
'Overtime/ Callback', 'Detail pay', 'Retro Pay', 'Other', | |
'Total')] <- apply(data[, c('Listed Salary', 'Base pay', 'Longevity', | |
'Overtime/ Callback', 'Detail pay', 'Retro Pay', 'Other', | |
'Total')], 2, | |
function(x) gsub(',', '', x)) | |
data[, c('Listed Salary', 'Base pay', 'Longevity', | |
'Overtime/ Callback', 'Detail pay', 'Retro Pay', 'Other', | |
'Total')] <- apply(data[, c('Listed Salary', 'Base pay', 'Longevity', | |
'Overtime/ Callback', 'Detail pay', 'Retro Pay', 'Other', | |
'Total')], 2, | |
as.numeric) | |
library(ggplot2) | |
library(scales) | |
ggplot(data, aes(`Base pay`, `Overtime/ Callback`)) + | |
geom_point() + | |
geom_vline(xintercept = 50000) + | |
scale_x_continuous('Base Pay', | |
labels = dollar) + | |
scale_y_continuous('Overtime or Callback Pay', | |
labels = dollar) + | |
theme_bw() + | |
ggtitle("Who Earns Overtime Pay?\nProvidence Firefighters") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment