library(here) # manage file pathslibrary(tidyverse) # your friend and minelibrary(cavax) # california vaccination exemption datalibrary(colorspace) # luminance-balanced paletteslibrary(demog) # demographic data for a graphlibrary(ggforce) # useful enhancements to ggplotlibrary(ggrepel) # Text and labelslibrary(patchwork) # compose multiple plotslibrary(scales) # scale adjustments and enhancementslibrary(socviz) # data and some useful functions
p_ylab <-"Amount Owed, in thousands of Dollars"p_title <-"Outstanding Student Loans"p_subtitle <-"44 million borrowers owe a total of $1.3 trillion"p_caption <-"Source: FRB NY"studebt <- studebt |>mutate(type_label =recode(type, "Borrowers"="Percent of all Borrowers","Balances"="Percent of all Balances"))studebt
# A tibble: 16 × 5
Debt type pct Debtrc type_label
<ord> <fct> <int> <ord> <fct>
1 Under $5 Borrowers 20 Under $5 Percent of all Borrowers
2 $5-$10 Borrowers 17 $5-$10 Percent of all Borrowers
3 $10-$25 Borrowers 28 $10-$25 Percent of all Borrowers
4 $25-$50 Borrowers 19 $25-$50 Percent of all Borrowers
5 $50-$75 Borrowers 8 $50-$75 Percent of all Borrowers
6 $75-$100 Borrowers 3 $75-$100 Percent of all Borrowers
7 $100-$200 Borrowers 4 $100-$200 Percent of all Borrowers
8 Over $200 Borrowers 1 Over $200 Percent of all Borrowers
9 Under $5 Balances 2 Under $5 Percent of all Balances
10 $5-$10 Balances 4 $5-$10 Percent of all Balances
11 $10-$25 Balances 15 $10-$25 Percent of all Balances
12 $25-$50 Balances 23 $25-$50 Percent of all Balances
13 $50-$75 Balances 16 $50-$75 Percent of all Balances
14 $75-$100 Balances 10 $75-$100 Percent of all Balances
15 $100-$200 Balances 19 $100-$200 Percent of all Balances
16 Over $200 Balances 11 Over $200 Percent of all Balances
Debt Plot 1
studebt
# A tibble: 16 × 5
Debt type pct Debtrc type_label
<ord> <fct> <int> <ord> <fct>
1 Under $5 Borrowers 20 Under $5 Percent of all Borrowers
2 $5-$10 Borrowers 17 $5-$10 Percent of all Borrowers
3 $10-$25 Borrowers 28 $10-$25 Percent of all Borrowers
4 $25-$50 Borrowers 19 $25-$50 Percent of all Borrowers
5 $50-$75 Borrowers 8 $50-$75 Percent of all Borrowers
6 $75-$100 Borrowers 3 $75-$100 Percent of all Borrowers
7 $100-$200 Borrowers 4 $100-$200 Percent of all Borrowers
8 Over $200 Borrowers 1 Over $200 Percent of all Borrowers
9 Under $5 Balances 2 Under $5 Percent of all Balances
10 $5-$10 Balances 4 $5-$10 Percent of all Balances
11 $10-$25 Balances 15 $10-$25 Percent of all Balances
12 $25-$50 Balances 23 $25-$50 Percent of all Balances
13 $50-$75 Balances 16 $50-$75 Percent of all Balances
14 $75-$100 Balances 10 $75-$100 Percent of all Balances
15 $100-$200 Balances 19 $100-$200 Percent of all Balances
16 Over $200 Balances 11 Over $200 Percent of all Balances
# A tibble: 16 × 5
Debt type pct Debtrc type_label
<ord> <fct> <int> <ord> <fct>
1 Under $5 Borrowers 20 Under $5 Percent of all Borrowers
2 $5-$10 Borrowers 17 $5-$10 Percent of all Borrowers
3 $10-$25 Borrowers 28 $10-$25 Percent of all Borrowers
4 $25-$50 Borrowers 19 $25-$50 Percent of all Borrowers
5 $50-$75 Borrowers 8 $50-$75 Percent of all Borrowers
6 $75-$100 Borrowers 3 $75-$100 Percent of all Borrowers
7 $100-$200 Borrowers 4 $100-$200 Percent of all Borrowers
8 Over $200 Borrowers 1 Over $200 Percent of all Borrowers
9 Under $5 Balances 2 Under $5 Percent of all Balances
10 $5-$10 Balances 4 $5-$10 Percent of all Balances
11 $10-$25 Balances 15 $10-$25 Percent of all Balances
12 $25-$50 Balances 23 $25-$50 Percent of all Balances
13 $50-$75 Balances 16 $50-$75 Percent of all Balances
14 $75-$100 Balances 10 $75-$100 Percent of all Balances
15 $100-$200 Balances 19 $100-$200 Percent of all Balances
16 Over $200 Balances 11 Over $200 Percent of all Balances
## This is not an efficient way to do thisaux_info |>select(mwc, info_schools, info_students) |>mutate(across(everything(), as.character)) |>group_by(mwc)
## This is not an efficient way to do thisaux_info |>select(mwc, info_schools, info_students) |>mutate(across(everything(), as.character)) |>group_by(mwc) |>group_keys()
# A tibble: 11 × 1
mwc
<chr>
1 Charter
2 Charter Montessori
3 Private Catholic
4 Private Christian
5 Private Christian Montessori
6 Private Jewish/Islamic
7 Private Montessori
8 Private Non-Specific
9 Private Waldorf
10 Public
11 Public Montessori
A little kludge
## This is not an efficient way to do thisaux_info |>select(mwc, info_schools, info_students) |>mutate(across(everything(), as.character)) |>group_by(mwc) |>group_keys() |>pull()
## This is not an efficient way to do thisaux_info |>select(mwc, info_schools, info_students) |>mutate(across(everything(), as.character)) |>group_by(mwc) |>group_keys() |>pull() |>as.character()
## This is not an efficient way to do thisaux_info |>select(mwc, info_schools, info_students) |>mutate(across(everything(), as.character)) |>group_by(mwc) |>group_keys() |>pull() |>as.character() -> keys
A little kludge
## This is not an efficient way to do thisaux_info |>select(mwc, info_schools, info_students) |>mutate(across(everything(), as.character)) |>group_by(mwc) |>group_keys() |>pull() |>as.character() -> keysaux_info
## This is not an efficient way to do thisaux_info |>select(mwc, info_schools, info_students) |>mutate(across(everything(), as.character)) |>group_by(mwc) |>group_keys() |>pull() |>as.character() -> keysaux_info |>select(mwc, info_schools, info_students)
## This is not an efficient way to do thisaux_info |>select(mwc, info_schools, info_students) |>mutate(across(everything(), as.character)) |>group_by(mwc) |>group_keys() |>pull() |>as.character() -> keysaux_info |>select(mwc, info_schools, info_students) |>mutate(across(everything(), as.character))
## This is not an efficient way to do thisaux_info |>select(mwc, info_schools, info_students) |>mutate(across(everything(), as.character)) |>group_by(mwc) |>group_keys() |>pull() |>as.character() -> keysaux_info |>select(mwc, info_schools, info_students) |>mutate(across(everything(), as.character)) |>group_split(mwc)
## This is not an efficient way to do thisaux_info |>select(mwc, info_schools, info_students) |>mutate(across(everything(), as.character)) |>group_by(mwc) |>group_keys() |>pull() |>as.character() -> keysaux_info |>select(mwc, info_schools, info_students) |>mutate(across(everything(), as.character)) |>group_split(mwc) |>set_names(keys) # There's a better way ...
## This is not an efficient way to do thisaux_info |>select(mwc, info_schools, info_students) |>mutate(across(everything(), as.character)) |>group_by(mwc) |>group_keys() |>pull() |>as.character() -> keysaux_info |>select(mwc, info_schools, info_students) |>mutate(across(everything(), as.character)) |>group_split(mwc) |>set_names(keys) |># There's a better way ...map_chr(.f = paste, sep ="", collapse ="\n")
## This is not an efficient way to do thisaux_info |>select(mwc, info_schools, info_students) |>mutate(across(everything(), as.character)) |>group_by(mwc) |>group_keys() |>pull() |>as.character() -> keysaux_info |>select(mwc, info_schools, info_students) |>mutate(across(everything(), as.character)) |>group_split(mwc) |>set_names(keys) |># There's a better way ...map_chr(.f = paste, sep ="", collapse ="\n") -> special_x_labs
A little kludge
## This is not an efficient way to do thisaux_info |>select(mwc, info_schools, info_students) |>mutate(across(everything(), as.character)) |>group_by(mwc) |>group_keys() |>pull() |>as.character() -> keysaux_info |>select(mwc, info_schools, info_students) |>mutate(across(everything(), as.character)) |>group_split(mwc) |>set_names(keys) |># There's a better way ...map_chr(.f = paste, sep ="", collapse ="\n") -> special_x_labs