---
title: 'US Projected Labor Force: 2000-2030'
author: "K. Gwet"
date: "`r Sys.Date()`"
output:
  pdf_document: default
  word_document: default
  html_document: default
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
library(tidyverse)
fra.lforce <- read_csv("../data/labor-force-stats.csv",
                       show_col_types = FALSE)
by.all <-fra.lforce%>%
  summarise(across(where(is.numeric),sum))
by.all.sex <- mutate(by.all,gender="All")[,c(5,1:4)]
by.gender <- fra.lforce%>%
  group_by(gender)%>%
  summarise(across(where(is.numeric),sum))
by.gender <- rbind(by.all.sex,by.gender)
```

## Some Labor Force Statistics

The labor force is expected to increase by **`r round((by.gender$LF2030[1] - by.gender$LF2020[1])/1000,1)`** million, from **`r round(by.gender$LF2020[1]/1000,1)`** million in 2020 to **`r round(by.gender$LF2030[1]/1000,1)`** million in 2030. 

For males aged 16 or older, the labor force is projected to increase by 
**`r round((by.gender$LF2030[2]-by.gender$LF2020[2])/1000,1)`** million  from **`r round(by.gender$LF2020[2]/1000,1)`** million in 2020 to **`r round(by.gender$LF2030[2] / 1000,1)`** million in 2030. 

For females aged 16 or more, that increase is higher and estimated at **`r round((by.gender$LF2030[3]-by.gender$LF2020[3])/1000,1)`** million  from **`r round(by.gender$LF2020[3]/1000,1)`** million in 2020 to **`r round(by.gender$LF2030[3] / 1000,1)`** million in 2030.

Here is the summary table of the size of the **US Labor Force** by gender:

```{r lfbysex}
knitr::kable(by.gender)
```

## Graphical Representation of the Predicted Labor Force

In this section, we will depict the predicted size of the labor force with a dodged bar chart, showing breakdowns by year and by gender. However, to create this bar chart, we first need to represent the predicted labor force statistics in a long format data table as follows:
```{r long-format-data}
laborforce.df <- 
  pivot_longer(by.gender,cols = !gender,
               names_to = "year", 
               values_to = "laborforce") %>%
  mutate(year=substr(year,3,nchar(year))) %>%
  select(year,gender,laborforce)
  knitr::kable(laborforce.df)
```

```{r average-rate}
all.lf <- by.gender[1,][2:5]
avrate <- ((all.lf[[2]]-all.lf[[1]])/all.lf[[1]] + 
             (all.lf[[3]]-all.lf[[2]])/all.lf[[2]] +
             (all.lf[[4]]-all.lf[[3]])/all.lf[[3]])/3
```
The dodged bar chart shown below, reveals that the number of males in the labor force will consistently exceeds the number of females throughout the year 2030. Moreover, the overall increase in size of the labor force will be steady at average rate of `r scales::percent(avrate)` per decade.

```{r barplot}
ggplot(laborforce.df, aes(x=year, y=laborforce, fill=gender)) + 
  geom_bar(stat="identity", position=position_dodge()) +
  theme_bw() +
  ylab("Labor Force (x1000)")
```