Explanation
For this exercise I am interested in looking at the trends in compensation for the non-financial corporate sector in the US and how this relates to overall profits within this industry.
I have sourced my data for this from the US Bureau of Labor statistics, with indexed and YoY deltas dating back to the late 1940s.
The selection of this data was primarily exploratory and I have charted the variables a couple different ways. This includes the index from the start of data collection to present to understand the relative growth rates of each of our measurements (Profit, Hourly Compensation, Hours Worked and Productivity). With this we can select out the different variables, as well as zoom in on specific time periods with the scale finder.
The second chart focuses on trends on Productivity, Compensation on the top chart vs. Profitability to allow for us to parse apart some of the potential relationships between the three variables over the past 70 years. The relationship between labor, compensation and profits is more complex than expected. Wage growth has been relatively low since the 1960s while productivity has been relatively flat. Interestingly, profits do show the highest growth YoY when wages are stagnating.
Source & BLS Specific Measures Key BLS measures are denoted below and can be found at their website: https://www.bls.gov/opub/hom/inp/concepts.htm Definitions for Labor Productivity and Hours Worked are sources from this page directly.
Labor productivity describes the relationship between the changes in the amount of output with the amount of labor used to produce that output. Labor productivity is expressed as an index, which is derived as a ratio of output growth to that of hours worked. Therefore, a change in labor productivity reflects the change in output that is not explained by the change in hours worked. Labor productivity can increase over time for many reasons, including technological advances, improved worker skills, improved management practices, economies of scale in production, and increases in the amount of nonlabor inputs used (capital, energy, materials, and purchased services).
Hours worked is the total number of annual hours worked of all people in an industry. This includes paid employees, the self-employed (partners and proprietors), and unpaid family workers (those who work in a family business or farm without pay).
Profits reported profits for specific sector for set time period (in this instance calendar year).
Hourly Compensation reported average hourly pay reported profits for specific sector for set time period (in this instance calendar year).
#load packages
library(dygraphs)
library(plotly)
## Loading required package: ggplot2
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(tidyverse)
## ── Attaching packages
## ───────────────────────────────────────
## tidyverse 1.3.2 ──
## ✔ tibble 3.1.8 ✔ purrr 0.3.4
## ✔ tidyr 1.2.0 ✔ stringr 1.4.0
## ✔ readr 2.1.2 ✔ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks plotly::filter(), stats::filter()
## ✖ dplyr::lag() masks stats::lag()
#set working director and pull in data
setwd("C:/Users/jschm/OneDrive/Desktop/Subterm 1/STAA 566 - Data Visualization/dynamic-graphs-jeffschmidt2")
labor <- read.csv("labor-productivity-major-sectors-csv.csv")
#convert our value of interest to numeric variable
labor_test <- labor %>%
mutate(Value2 = as.numeric(Value))
## Warning in mask$eval_all_mutate(quo): NAs introduced by coercion
#manipulate data so it can be processed column-wise
labor_test <- labor_test %>%
group_by(Measure)%>%
mutate(row = row_number())
labor_test <- labor_test %>%
tidyr::pivot_wider(names_from = Measure, values_from = Value2)
#format labels
names(labor_test) <- gsub(" ", "_",names(labor_test))
#filter our relevant cases for non-fin sector, unit and time period of interest
labor_test <- labor_test %>%
filter(Basis == "Employees") %>%
filter(Sector == "Nonfinancial corporate sector") %>%
filter(Qtr == "Annual") %>%
filter(Units == "Index (2012=100)")
labor_test
## # A tibble: 1,633 × 31
## Sector Basis Units Year Qtr Value row Labor…¹ Real_…² Hours…³ Hourl…⁴
## <chr> <chr> <chr> <int> <chr> <chr> <int> <dbl> <dbl> <dbl> <dbl>
## 1 Nonfinan… Empl… Inde… 1947 Annu… 22.4… 5854 22.5 NA NA NA
## 2 Nonfinan… Empl… Inde… 1948 Annu… 23.9… 5855 24.0 NA NA NA
## 3 Nonfinan… Empl… Inde… 1949 Annu… 25.2… 5856 25.3 NA NA NA
## 4 Nonfinan… Empl… Inde… 1950 Annu… 27.1… 5857 27.2 NA NA NA
## 5 Nonfinan… Empl… Inde… 1951 Annu… 26.8… 5858 26.9 NA NA NA
## 6 Nonfinan… Empl… Inde… 1952 Annu… 27.5… 5859 27.5 NA NA NA
## 7 Nonfinan… Empl… Inde… 1953 Annu… 28.6… 5860 28.7 NA NA NA
## 8 Nonfinan… Empl… Inde… 1954 Annu… 29.9… 5861 29.9 NA NA NA
## 9 Nonfinan… Empl… Inde… 1955 Annu… 31.6… 5862 31.7 NA NA NA
## 10 Nonfinan… Empl… Inde… 1956 Annu… 31.8… 5863 31.9 NA NA NA
## # … with 1,623 more rows, 20 more variables: Employment <dbl>,
## # Real_hourly_compensation <dbl>, Average_weekly_hours <dbl>,
## # Unit_labor_costs <dbl>, Unit_nonlabor_payments <dbl>, Labor_share <dbl>,
## # Labor_compensation <dbl>, `Value-added_output_price_deflator` <dbl>,
## # `Value-added_output` <dbl>, Nonlabor_payments <dbl>,
## # Output_per_worker <dbl>, Consumer_price_deflator <dbl>,
## # Unit_nonlabor_costs <dbl>, Unit_combined_input_costs <dbl>, …
## # ℹ Use `print(n = ...)` to see more rows, and `colnames()` to see all variable names
#comparing four measures of interest
lab_plty2 <- plot_ly(labor_test, x = ~Year)%>%
add_lines(y = ~Labor_productivity, name = "Labor Productivity")%>%
add_lines(y = ~Hours_worked, name = "Hours Worked")%>%
add_lines(y = ~Hourly_compensation, name = "Hourly Compensation")%>%
add_lines(y = ~Profits, name = "Profits")
#add range slider, labels and title
lab_plty2 <- lab_plty2%>%
rangeslider()%>%
layout(hovermode = "x",
title = list(text = "Profits, Hours & Compensation for Non-Fin Corporate Sector (Indexed vs. 2012)", font = 8),
yaxis = list(title = "Metric Index (2012=100)",
xaxis = list(title = "Year"),
annotations = list(text = "Source: US Bureau of Labor Statistics",
showarrow = FALSE,
xref='paper',
yref='paper')))
#generate plot
lab_plty2
#convert our value of interest to numeric variable
labor_test2 <- labor %>%
mutate(Value2 = as.numeric(Value))
## Warning in mask$eval_all_mutate(quo): NAs introduced by coercion
#manipulate data so it can be processed column-wise
labor_test2 <- labor_test2 %>%
group_by(Measure)%>%
mutate(row = row_number())
labor_test2 <- labor_test2 %>%
tidyr::pivot_wider(names_from = Measure, values_from = Value2)
#format labels
names(labor_test2) <- gsub(" ", "_",names(labor_test))
labor_test2 <- labor_test2 %>%
filter(Basis == "Employees") %>%
filter(Sector == "Nonfinancial corporate sector") %>%
filter(Qtr == "Annual") %>%
filter(Units == "% Change from previous year")
labor_test2
## # A tibble: 1,499 × 31
## Sector Basis Units Year Qtr Value row Labor…¹ Real_…² Hours…³ Hourl…⁴
## <chr> <chr> <chr> <int> <chr> <chr> <int> <dbl> <dbl> <dbl> <dbl>
## 1 Nonfinan… Empl… % Ch… 1947 Annu… N.A. 5779 NA NA NA NA
## 2 Nonfinan… Empl… % Ch… 1948 Annu… 6.8 5780 6.8 NA NA NA
## 3 Nonfinan… Empl… % Ch… 1949 Annu… 5.4 5781 5.4 NA NA NA
## 4 Nonfinan… Empl… % Ch… 1950 Annu… 7.4 5782 7.4 NA NA NA
## 5 Nonfinan… Empl… % Ch… 1951 Annu… -0.9 5783 -0.9 NA NA NA
## 6 Nonfinan… Empl… % Ch… 1952 Annu… 2.4 5784 2.4 NA NA NA
## 7 Nonfinan… Empl… % Ch… 1953 Annu… 4.1 5785 4.1 NA NA NA
## 8 Nonfinan… Empl… % Ch… 1954 Annu… 4.3 5786 4.3 NA NA NA
## 9 Nonfinan… Empl… % Ch… 1955 Annu… 5.9 5787 5.9 NA NA NA
## 10 Nonfinan… Empl… % Ch… 1956 Annu… 0.6 5788 0.6 NA NA NA
## # … with 1,489 more rows, 20 more variables: Employment <dbl>,
## # Real_hourly_compensation <dbl>, Average_weekly_hours <dbl>,
## # Unit_labor_costs <dbl>, Unit_nonlabor_payments <dbl>, Labor_share <dbl>,
## # Labor_compensation <dbl>, `Value-added_output_price_deflator` <dbl>,
## # `Value-added_output` <dbl>, Nonlabor_payments <dbl>,
## # Output_per_worker <dbl>, Consumer_price_deflator <dbl>,
## # Unit_nonlabor_costs <dbl>, Unit_combined_input_costs <dbl>, …
## # ℹ Use `print(n = ...)` to see more rows, and `colnames()` to see all variable names
#add range slider, labels and title as well as facets for Labor Figures vs. Profit
lab_plty_hours <- plot_ly(labor_test2, x = ~Year)%>%
add_lines(y = ~Labor_productivity, name = "Labor Productivity")%>%
add_lines(y = ~Hourly_compensation, name = "Hourly Compensation")
lab_plty_profit <- plot_ly(labor_test2,
x = ~Year,
y = ~Profits,
name = "Profits",
type = "scatter",
mode = "lines")
lab_plty_facet <- subplot(list(lab_plty_hours,lab_plty_profit),
nrows = 2,
shareX = TRUE,
titleX = FALSE)%>%
rangeslider()%>%
layout(hovermode = "X",
title = "Profits, Productivity and Compensation, % Growth vs. Previous year",
xaxis = list(title = "Year"),
yaxis = list(title = "% Growth vs. YAGO"),
annotations = list(text = "Source: US Bureau of Labor Statistics",
showarrow = FALSE,
xref='paper',
yref='paper'))
#print chart
lab_plty_facet