R script used to create DFW Wage Explorer tool.
library(dplyr)
library(reshape)
library(magrittr)
library(DT)
names(wages_in) <- c("SOC", "description", "mean", "pct10", "pct25", "median", "pct75", "pct90",
"emp2020", "emp2023", "education", "experience", "ojt", "completions")
wages_in$empchange <- wages_in$emp2023-wages_in$emp2020
wages_in$empchangepct <- wages_in$emp2023/wages_in$emp2020-1
wages_in <- wages_in[c(1:10,15:16,11:14)]
library(plotly)
library(crosstalk)
wages <- highlight_key(wages_in)
widgets1 <- bscols(
widths = c(12,12,12),
filter_select("education", "Entry Level Education", wages, ~education),
filter_select("experience", "Work Experience Required", wages, ~experience),
filter_select("ojt", "On-the-Job Training", wages, ~ojt)
)
widgets2 <- bscols(
widths = c(12,12,12,12,12),
filter_slider("10pct", "10th Pct. Hourly Wage", wages, ~pct10, round = 2, pre = "$"),
filter_slider("25pct", "25th Pct. Hourly Wage", wages, ~pct25, round = 2, pre = "$"),
filter_slider("median", "Median Hourly Wage", wages, ~median, round = 2, pre = "$"),
filter_slider("75pct", "75th Pct. Hourly Wage", wages, ~pct75, round = 2, pre = "$"),
filter_slider("90pct", "90th Pct. Hourly Wage", wages, ~pct90, round = 2, pre = "$")
)
widgets3 <-bscols(
widths = c(12,12,12,12),
filter_slider("emp2020", "Employment (2020)", wages, ~emp2020, round = TRUE, sep = ","),
filter_slider("emp2023", "Employment (2023)", wages, ~emp2023, round = TRUE, sep = ","),
filter_slider("empchange", "Emp. Change, 2020 to 2023", wages, ~empchange, round = TRUE, sep = ","),
filter_slider("empchangepct", "Emp. Change (%), 2020 to 2023", wages, ~empchangepct*100, round = TRUE, post = "%")
)
fig <- bscols(
widths = c(6,2,2,2,12),
plot_ly(height = 600,
wages, x = ~median, y = ~median, name = 'Median',
type = 'scatter', mode = 'lines',
hovertemplate = ~paste0(SOC, ': ', description,
'<br>', 'Median Wage: <b>%{y:$,.2f}</b>/hr.',
'<extra></extra>')) %>%
add_trace(y = ~pct10, name = '10th Percentile', mode = 'markers',
hovertemplate = ~paste0(SOC, ': ', description,
'<br>', '10th Pct. Wage: <b>%{y:$,.2f}</b>/hr.',
'<extra></extra>')) %>%
add_trace(y = ~pct25, name = '25th Percentile', mode = 'markers',
hovertemplate = ~paste0(SOC, ': ', description,
'<br>', '25th Pct. Wage: <b>%{y:$,.2f}</b>/hr.',
'<extra></extra>')) %>%
add_trace(y = ~pct75, name = '75th Percentile', mode = 'markers',
hovertemplate = ~paste0(SOC, ': ', description,
'<br>', '75th Pct. Wage: <b>%{y:$,.2f}</b>/hr.',
'<extra></extra>')) %>%
add_trace(y = ~pct90, name = '90th Percentile', mode = 'markers',
hovertemplate = ~paste0(SOC, ': ', description,
'<br>', '90th Pct. Wage: <b>%{y:$,.2f}</b>/hr.',
'<extra></extra>')) %>%
layout(
title = "Wage by Occupation (DFW, 2020)",
# margin = 10,
xaxis = list(title = "Median Hourly Wage"),
yaxis = list(title = "Hourly Wage (See Legend)"),
legend = list(orientation = 'h', x=0, y=1)
),
widgets1,
widgets2,
widgets3,
datatable(wages,
# width = 1750,
extensions = c('Buttons'),
options = list(
columnDefs = list(list(className = 'dt-center', targets = 0:15)),
lengthMenu = c(10,25,50,100,1000),
dom = 'Bfrtip',
buttons = c('copy', 'excel')
),
rownames = FALSE,
colnames = c("SOC", "Occupation", "Mean Wage ($/hr.)",
"10th Pct. Wage ($/hr.)", "25th Pct. Wage ($/hr.)", "Median Wage ($/hr.)",
"75th Pct. Wage ($/hr.)", "90th Pct. Wage ($/hr.)",
"2020 Employment", "2023 Employment", "Emp. Change, 2020 to 2023",
"Emp. Change (%), 2020 to 2023",
"Entry Level Education", "Work Experience Required",
"On-the-Job Training", "Regional Completions"),
caption = htmltools::tags$caption(
style = 'caption-side: bottom; text-align: center;',
'Source: ', htmltools::em('Emsi.'))
) %>%
formatCurrency(3:8, currency = "$", interval = 3, mark = ",", digits = 2) %>%
formatRound(c(9:11,16), digits = 0, interval = 3, mark = ",") %>%
formatPercentage(12, digits = 0)
)
Rachel Brasier
rachelabrasier.com
15 January 2021