MENU

Fun & Interesting

Using ggplot2 to quantify the change in the US poverty rate over the last 65 years in R (CC334)

Riffomonas Project 1,091 3 months ago
Video Not Working? Fix It Now

Pat recreates a figure showing the change in the number and percent of people in the US who live in poverty for the past 65 years in honor of National Poverty Awareness Month. He pulls this off using tools from ggplot2, dplyr, readxl, jsonlite, ggtext, and showtext. The functions he uses from these packages include font_add_google, showtext_auto, showtext_opts, select, filter, mutate, pivot_longer, inner_join, str_replace, case_when, row_number, paste, year, yday, read_excel, geom_rect, geom_hline, geom_line, geom_text, facet_wrap, labeller, labs, scale_color_manual, scale_fill_manual, scale_y_continuous, scale_x_continuous, coord_cartesian, guides, guide_axis, theme_classic, and theme. You can find the data and code he developed in this episode at https://www.riffomonas.org/code_club/2025-01-20-poverty-recreate. Pat's newsletter describing how he would go about generating the figure can be found at https://shop.riffomonas.org/posts/tracking-trends-in-poverty-with-ggplot2. The recession data can be found at https://data.nber.org and the poverty data can be found at https://www.census.gov/data/tables/time-series/demo/income-poverty/historical-poverty-people.html. The xlsx file can be downloaded from https://www2.census.gov/programs-surveys/cps/tables/time-series/historical-poverty-people/hstpov2.xlsx. If you have a figure that you would like to see me discuss in a future newsletter and episode of Code Club, email me at [email protected]! Want more practice on the concepts covered in Code Club? You can sign up for my weekly newsletter at https://shop.riffomonas.org/youtube to get practice problems, tips, and insights. If you're interested in purchasing a video workshop be sure to check out https://riffomonas.org/workshops/ Support Riffomonas by becoming a Patreon member! https://www.patreon.com/riffomonas You can also find complete tutorials for learning R with the tidyverse using... Microbial ecology data: https://www.riffomonas.org/minimalR/ General data: https://www.riffomonas.org/generalR/ If you want to cite this video, please consider citing https://journals.asm.org/doi/10.1128/mra.01310-22 0:00 Introduction 6:39 Loading and wrangling data with dplyr 16:01 Creating faceted line plot with two colors 20:49 Indicating recessions with background rectangles 30:17 Creating titles and labels 32:16 Formatting x-axis 37:14 Styling appearance of figure 42:20 Adding grid lines and formatting axis appearance 48:30 Annotating lines in right-hand margin 54:59 Creating and placing legend

Comment