TT: Wealth and Income

R
tidyTuesday
tidyverse
Author

Robert W. Walker

Published

February 8, 2021

Code
library(tidyverse)
library(readr)
library(hrbrthemes)

tidyTuesday-Screenshot

tidyTuesday for the week of February 8, 2021 brings data from the US Census and the Urban Institute together to think about income, wealth, and racial inequality in these and other important economic indicators. There is a lot of data that they make available to accompany the nine charts about wealth inequality that they reported here. There is considerable variation in the scope and coverage of the various datasets; I will start by loading the ten datasets.

Code
lifetime_earn <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-02-09/lifetime_earn.csv')
student_debt <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-02-09/student_debt.csv')
retirement <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-02-09/retirement.csv')
home_owner <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-02-09/home_owner.csv')
race_wealth <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-02-09/race_wealth.csv')
income_time <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-02-09/income_time.csv')
income_limits <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-02-09/income_limits.csv')
income_aggregate <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-02-09/income_aggregate.csv')
income_distribution <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-02-09/income_distribution.csv')
income_mean <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-02-09/income_mean.csv')

Lifetime Earnings

There is not all that much data here. Six values for the cross-tabulation of race and gender.

Code
lifetime_earn %>% 
  ggplot() + 
  aes(x=race, y=lifetime_earn/1000000, fill=race) + 
  geom_col() + coord_flip() + 
  facet_wrap(vars(gender)) + 
  scale_fill_viridis_d() + theme_ipsum_tw() + 
  labs(y="Lifetime Earnings [in millions]")

Combining the categories offers a considerably improved visual in my view.

Code
lifetime_earn %>% 
  mutate(Categ = paste(race,gender,sep=":")) %>% 
  ggplot() + 
  aes(x=Categ, y=lifetime_earn/1000000, fill=race, color=race, label=lifetime_earn/1000000, alpha=0.2) + 
  geom_col() + geom_text(size=3, color="white", alpha=1) + 
  coord_flip() + scale_color_ipsum() + scale_fill_ipsum() + 
  theme_modern_rc() + 
  labs(y="Lifetime Earnings [in millions]", x="Race:Gender") + 
  guides(fill=FALSE, color=FALSE, alpha=FALSE)

Code
lifetime_earn %>% 
  mutate(Categ = paste(gender,race,sep=":")) %>% 
  ggplot() + 
  aes(x=Categ, y=lifetime_earn/1000000, fill=race, color=race, label=lifetime_earn/1000000, alpha=0.2) + 
  geom_col() + geom_text(size=3, color="white", alpha=1) + 
  coord_flip() + scale_color_ipsum() + scale_fill_ipsum() + 
  theme_modern_rc() + 
  labs(y="Lifetime Earnings [in millions]", x="Race:Gender") +
  guides(fill=FALSE, color=FALSE, alpha=FALSE)

Student Debt

The student debt data is not super extensive. At three year intervals, we see growth across categories but higher levels and rates are notable by racial category. A line plot is a good place to start.

Code
student_debt %>% ggplot() + 
  aes(x=year, y=loan_debt_pct, color=race) + 
  geom_line() + geom_point(size=3) + 
  scale_color_viridis_d() + 
  labs(y="Share of Families with Student Loan Debt") + 
  theme_ipsum_rc()

A faceted bar plot.

Code
student_debt %>% ggplot() + 
  aes(x=race, y=loan_debt_pct, fill=race) + 
  geom_col() + scale_color_viridis_d() + 
  labs(y="Share of Families with Student Loan Debt") + 
  guides(fill=FALSE) + theme_ipsum_rc() + 
  coord_flip() + facet_wrap(vars(year))

Retirement

Liquid retirement savings offer an interesting basis for comparison.

Code
retirement %>% ggplot() + 
  aes(x=year, y=retirement, color=race) + 
  geom_line() + geom_point() + 
  scale_color_ipsum() + theme_ipsum_rc() + 
  labs(y="Liquid Retirment Savings", color="Race")

References

Code
knitr::write_bib(names(sessionInfo()$otherPkgs), file="bibliography.bib")

References

Müller, Kirill, and Hadley Wickham. 2022. Tibble: Simple Data Frames. https://CRAN.R-project.org/package=tibble.
Rudis, Bob. 2020. Hrbrthemes: Additional Themes, Theme Components and Utilities for Ggplot2. http://github.com/hrbrmstr/hrbrthemes.
Wickham, Hadley. 2016. Ggplot2: Elegant Graphics for Data Analysis. Springer-Verlag New York. https://ggplot2.tidyverse.org.
———. 2022a. Stringr: Simple, Consistent Wrappers for Common String Operations. https://CRAN.R-project.org/package=stringr.
———. 2022b. Tidyverse: Easily Install and Load the Tidyverse. https://CRAN.R-project.org/package=tidyverse.
———. 2023. Forcats: Tools for Working with Categorical Variables (Factors). https://CRAN.R-project.org/package=forcats.
Wickham, Hadley, Mara Averick, Jennifer Bryan, Winston Chang, Lucy D’Agostino McGowan, Romain François, Garrett Grolemund, et al. 2019. “Welcome to the tidyverse.” Journal of Open Source Software 4 (43): 1686. https://doi.org/10.21105/joss.01686.
Wickham, Hadley, Winston Chang, Lionel Henry, Thomas Lin Pedersen, Kohske Takahashi, Claus Wilke, Kara Woo, Hiroaki Yutani, and Dewey Dunnington. 2023. Ggplot2: Create Elegant Data Visualisations Using the Grammar of Graphics. https://CRAN.R-project.org/package=ggplot2.
Wickham, Hadley, Romain François, Lionel Henry, Kirill Müller, and Davis Vaughan. 2023. Dplyr: A Grammar of Data Manipulation. https://CRAN.R-project.org/package=dplyr.
Wickham, Hadley, and Lionel Henry. 2023. Purrr: Functional Programming Tools. https://CRAN.R-project.org/package=purrr.
Wickham, Hadley, Jim Hester, and Jennifer Bryan. 2023. Readr: Read Rectangular Text Data. https://CRAN.R-project.org/package=readr.
Wickham, Hadley, Davis Vaughan, and Maximilian Girlich. 2023. Tidyr: Tidy Messy Data. https://CRAN.R-project.org/package=tidyr.