• Steven Ponce
  • About
  • Data Visualizations
  • Projects
  • Resume
  • Email

On this page

  • Steps to Create this Graphic
    • 1. Load Packages & Setup
    • 2. Read in the Data
    • 3. Examine the Data
    • 4. Tidy Data
    • 5. Visualization Parameters
    • 6. Plot
    • 7. Save
    • 8. Session Info
    • 9. GitHub Repository
    • 10. References
    • 11. Custom Functions Documentation

The Crime Wave May Have Been Written in 1970

  • Show All Code
  • Hide All Code

  • View Source

Indexed U.S. trends in leaded gasoline use and violent crime rates** reveal a ~22-year lag. Both series indexed to peak (= 100) to compare shape, not magnitude. Children exposed to lead in early life reach peak offending age ~20 years later.

30DayChartChallenge
Data Visualization
R Programming
2026
A dual-line chart exploring the lead-crime hypothesis: U.S. trends in leaded gasoline use and violent crime rates, indexed, reveal a striking ~22-year lag. Both series are normalized to their own peak (= 100) to compare shape and timing, not magnitude. Built with ggplot2 in R as part of the #30DayChartChallenge 2026 — Day 16: Causation.
Author

Steven Ponce

Published

April 16, 2026

Figure 1: Line chart showing indexed U.S. trends in leaded gasoline use (red) and violent crime rates (dark) from 1941 to 2010, both normalized to peak = 100. Leaded gasoline peaked around 1970 and declined sharply after the EPA regulation began in 1973. Violent crime peaks around 1991 — approximately 22 years later — then falls steadily. A shaded band and arrow highlight the lag window between the two peaks, illustrating the hypothesis that early-life lead exposure shaped the U.S. crime wave two decades later.

Steps to Create this Graphic

1. Load Packages & Setup

Show code
```{r}
#| label: load
#| warning: false
#| message: false      
#| results: "hide"     

## 1. LOAD PACKAGES & SETUP ----
suppressPackageStartupMessages({
pacman::p_load(
  tidyverse, ggtext, showtext,  
  janitor, scales, glue
  )
})

### |- figure size ----
camcorder::gg_record(
  dir    = here::here("temp_plots"),
  device = "png",
  width  = 12,
  height = 8,
  units  = "in",
  dpi    = 320
)

# Source utility functions
suppressMessages(source(here::here("R/utils/fonts.R")))
source(here::here("R/utils/social_icons.R"))
source(here::here("R/utils/image_utils.R"))
source(here::here("R/themes/base_theme.R"))
```

2. Read in the Data

Show code
```{r}
#| label: read
#| include: true
#| eval: true
#| warning: false

### |- leaded gasoline use (US, indexed: peak 1970 = 100) ----
### Values derived from Nevin (2000, 2007) Figure 1 data and EPA records.
### Units: thousands of short tons of lead emitted annually, normalized to peak.
### The series rises through the 1940s–60s as car ownership expands,
### peaks ~1970 at ~200,000 tons/year, then falls sharply after EPA phasedown
### begins 1973, accelerating in 1985 (90% reduction rule) and ban in 1996.

lead_raw <- tibble(
  year  = c(1941, 1945, 1950, 1955, 1960, 1963, 1965, 1967, 1969, 1970,
            1971, 1972, 1973, 1974, 1975, 1976, 1977, 1978, 1979, 1980,
            1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989, 1990,
            1991, 1992, 1993, 1994, 1995),
  lead  = c(  9,   11,   32,   52,   70,   80,   88,   93,   97,  100,
              99,   97,   94,   90,   83,   75,   68,   62,   57,   53,
              49,   43,   37,   30,   18,    9,    6,    5,    4,    3,
              2,    2,    1,    1,    1)
)

### |- FBI UCR violent crime rate per 100,000 (1960–2010) ----
### Source: FBI Uniform Crime Reporting Program.
### Violent crime = murder, rape (legacy def.), robbery, aggravated assault.
### Values rounded to nearest whole number from published FBI tables.
### Peak: ~758 per 100,000 in 1991.

crime_raw <- tibble(
  year  = c(1960, 1961, 1962, 1963, 1964, 1965, 1966, 1967, 1968, 1969,
            1970, 1971, 1972, 1973, 1974, 1975, 1976, 1977, 1978, 1979,
            1980, 1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989,
            1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
            2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
            2010),
  crime = c(161, 158, 162, 168, 190, 200, 220, 253, 298, 329,
            364, 396, 401, 417, 461, 482, 467, 476, 497, 549,
            597, 594, 571, 538, 539, 557, 617, 610, 640, 664,
            730, 758, 758, 747, 714, 685, 637, 611, 567, 524,
            507, 505, 494, 475, 463, 469, 474, 467, 455, 431,
            405)
)
```

3. Examine the Data

Show code
```{r}
#| label: examine
#| include: true
#| eval: true
#| results: 'hide'
#| warning: false

glimpse(lead_raw)
glimpse(crime_raw)

### Check peak years
lead_raw  |> slice_max(lead,  n = 3)   
crime_raw |> slice_max(crime, n = 3)  
```

4. Tidy Data

Show code
```{r}
#| label: tidy
#| warning: false

### |- Normalize each series: peak = 100 ----
lead_idx <- lead_raw |>
  mutate(
    index = lead / max(lead) * 100,
    series = "lead"
  )

crime_idx <- crime_raw |>
  mutate(
    index = crime / max(crime) * 100,
    series = "crime"
  )

### |- Combine for plotting ----
df_plot <- bind_rows(
  lead_idx |> select(year, index, series),
  crime_idx |> select(year, index, series)
) |>
  mutate(
    series = factor(series, levels = c("lead", "crime")),
    series_label = case_when(
      series == "lead" ~ "Leaded gasoline use",
      series == "crime" ~ "Violent crime rate"
    )
  )

### |- Annotation anchor points ----
lead_peak_year <- lead_raw |>
  slice_max(lead, n = 1) |>
  pull(year) # 1970
crime_peak_year <- crime_raw |>
  slice_max(crime, n = 1, with_ties = FALSE) |>
  pull(year) # 1991

lead_peak_idx <- 100
crime_peak_idx <- 100

### |- Key annotation coordinates ----
lag_xmin <- lead_peak_year # 1970
lag_xmax <- crime_peak_year # 1991
```

5. Visualization Parameters

Show code
```{r}
#| label: params
#| include: true
#| warning: false

### |- Plot aesthetics ----
colors <- get_theme_colors(
  palette = list(
    "lead"       = "#C0392B",  
    "crime"      = "#1C2833",  
    "lag_band"   = "#F0E6C8",  
    "annotation" = "#555555"   
  )
)

### |- Titles and caption ----
title_text <- "The Crime Wave May Have Been Written in 1970"

subtitle_text <- glue(
  "Indexed U.S. trends in **<span style='color:{colors$palette$lead}'>leaded gasoline use</span>** ",
  "and **<span style='color:{colors$palette$crime}'>violent crime rates</span>** ",
  "reveal a ~22-year lag.<br>",
  "Both series indexed to peak (= 100) to compare shape, not magnitude. ",
  "Children exposed to lead in early life reach peak offending age ~20 years later."
)

caption_text <- create_dcc_caption(
  dcc_year    = 2026,
  dcc_day     = 16,
  source_text = "FBI Uniform Crime Reporting Program; Nevin (2007) Environ. Res.; EPA lead phasedown records"
)

### |- Fonts ----
setup_fonts()
fonts <- get_font_families()

### |- base theme ----
base_theme <- create_base_theme(colors)

weekly_theme <- extend_weekly_theme(
  base_theme,
  theme(
    # Titles
    plot.title  = element_text(
      size = 26, face = "bold", family = fonts$title,
      color = colors$palette$crime, margin = margin(b = 6)
    ),
    plot.subtitle = element_markdown(
      size = 11, family = fonts$text,
      color = "#444444", lineheight = 1.4,
      margin = margin(b = 18)
    ),
    plot.caption  = element_markdown(
      size = 9, color = "gray50", hjust = 0,
      margin = margin(t = 14)
    ),
    
    # Axes
    axis.title.x = element_blank(),
    axis.title.y = element_text(
      size = 11, color = "gray45", family = fonts$text,
      margin = margin(r = 8), lineheight = 1.3
    ),
    axis.text = element_text(size = 10, color = "gray40", family = fonts$text),
    axis.ticks = element_blank(),
    
    # Grid — horizontal only, very light
    panel.grid.major.x = element_blank(),
    panel.grid.minor = element_blank(),
    panel.grid.major.y = element_line(color = "gray92", linewidth = 0.3),
    
    # Panel
    panel.background = element_rect(fill = "white", color = NA),
    plot.background = element_rect(fill = "white", color = NA),
    plot.margin = margin(20, 24, 12, 20)
  )
)

theme_set(weekly_theme)
```

6. Plot

Show code
```{r}
#| label: plot
#| warning: false

### |- main plot ----
p <- ggplot() +

  # Lag band
  annotate(
    "rect",
    xmin = lag_xmin, xmax = lag_xmax,
    ymin = -Inf, ymax = Inf,
    fill = colors$palette$lag_band, alpha = 0.35
  ) +

  # Geoms
  geom_line(
    data = df_plot |> filter(series == "lead"),
    aes(x = year, y = index),
    color = colors$palette$lead, linewidth = 1.1, lineend = "round"
  ) +
  geom_line(
    data = df_plot |> filter(series == "crime"),
    aes(x = year, y = index),
    color = colors$palette$crime, linewidth = 1.25, lineend = "round"
  ) +
  geom_point(
    data = tibble(year = lead_peak_year, index = lead_peak_idx, series = "lead"),
    aes(x = year, y = index),
    color = colors$palette$lead, size = 3.5
  ) +
  geom_point(
    data = tibble(year = crime_peak_year, index = crime_peak_idx, series = "crime"),
    aes(x = year, y = index),
    color = colors$palette$crime, size = 3.5
  ) +

  # Annotate
  annotate(
    "text",
    x = lead_peak_year - 1, y = lead_peak_idx + 5,
    label = "Lead peaks\n~1970",
    hjust = 1, vjust = 0, size = 4.1,
    color = colors$palette$lead, fontface = "bold"
  ) +
  annotate(
    "text",
    x = 1992, y = crime_peak_idx + 5,
    label = "Crime peaks\n~1991",
    hjust = 0, vjust = 0, size = 4.1,
    color = colors$palette$crime, fontface = "bold"
  ) +
  annotate(
    "segment",
    x = lag_xmin + 0.5, xend = lag_xmax - 0.5,
    y = 28, yend = 28,
    arrow = arrow(ends = "both", length = unit(0.12, "cm"), type = "closed"),
    color = "#8B6914", linewidth = 0.55
  ) +
  annotate(
    "text",
    x = (lag_xmin + lag_xmax) / 2, y = 36,
    label = "~22-year lag (exposure \u2192 peak offending age)",
    hjust = 0.5, size = 2.9,
    color = "#8B6914", fontface = "bold", family = "sans"
  ) +
  annotate(
    "segment",
    x = 1973, xend = 1973,
    y = 0, yend = 93,
    linetype = "dashed", color = "gray65", linewidth = 0.4
  ) +
  annotate(
    "text",
    x = 1972.2, y = 78,
    label = "EPA lead phaseout\nbegins (1973)",
    hjust = 1, size = 3.2, lineheight = 1.25,
    color = "gray35"
  ) +

  # Scales
  scale_x_continuous(
    breaks = seq(1945, 2010, by = 10),
    expand = expansion(mult = c(0.02, 0.02))
  ) +
  scale_y_continuous(
    limits = c(0, 115),
    breaks = seq(0, 100, by = 25),
    labels = function(x) ifelse(x == 100, "100\n(peak)", as.character(x)),
    expand = expansion(mult = c(0.01, 0.05))
  ) +
  # Labs
  labs(
    title    = title_text,
    subtitle = subtitle_text,
    caption  = caption_text,
    y        = "Index (peak = 100)"
  )
```

7. Save

Show code
```{r}
#| label: save
#| warning: false

### |-  plot image ----  
save_plot(
  p, 
  type = "30daychartchallenge", 
  year = 2026, 
  day = 16, 
  width = 12, 
  height = 8
  )
```

8. Session Info

TipExpand for Session Info
R version 4.3.1 (2023-06-16 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 11 x64 (build 26100)

Matrix products: default


locale:
[1] LC_COLLATE=English_United States.utf8 
[2] LC_CTYPE=English_United States.utf8   
[3] LC_MONETARY=English_United States.utf8
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.utf8    

time zone: America/New_York
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] here_1.0.2      glue_1.8.0      scales_1.4.0    janitor_2.2.1  
 [5] showtext_0.9-7  showtextdb_3.0  sysfonts_0.8.9  ggtext_0.1.2   
 [9] lubridate_1.9.5 forcats_1.0.1   stringr_1.6.0   dplyr_1.2.0    
[13] purrr_1.2.1     readr_2.2.0     tidyr_1.3.2     tibble_3.2.1   
[17] ggplot2_4.0.2   tidyverse_2.0.0

loaded via a namespace (and not attached):
 [1] gtable_0.3.6       xfun_0.56          htmlwidgets_1.6.4  tzdb_0.5.0        
 [5] vctrs_0.7.1        tools_4.3.1        generics_0.1.4     curl_7.0.0        
 [9] gifski_1.32.0-2    pacman_0.5.1       pkgconfig_2.0.3    RColorBrewer_1.1-3
[13] S7_0.2.0           lifecycle_1.0.5    compiler_4.3.1     farver_2.1.2      
[17] textshaping_1.0.4  codetools_0.2-19   snakecase_0.11.1   litedown_0.9      
[21] htmltools_0.5.9    yaml_2.3.12        pillar_1.11.1      camcorder_0.1.0   
[25] magick_2.8.6       commonmark_2.0.0   tidyselect_1.2.1   digest_0.6.39     
[29] stringi_1.8.7      rsvg_2.6.2         rprojroot_2.1.1    fastmap_1.2.0     
[33] grid_4.3.1         cli_3.6.5          magrittr_2.0.3     withr_3.0.2       
[37] timechange_0.4.0   rmarkdown_2.30     otel_0.2.0         ragg_1.5.0        
[41] hms_1.1.4          evaluate_1.0.5     knitr_1.51         markdown_2.0      
[45] rlang_1.1.7        gridtext_0.1.6     Rcpp_1.1.1         xml2_1.5.2        
[49] svglite_2.1.3      rstudioapi_0.18.0  jsonlite_2.0.0     R6_2.6.1          
[53] systemfonts_1.3.2 

9. GitHub Repository

TipExpand for GitHub Repo

The complete code for this analysis is available in 30dcc_2026_16.qmd.

For the full repository, click here.

10. References

TipExpand for References
  1. Data Sources:
    • Federal Bureau of Investigation. Uniform Crime Reporting (UCR) Program — Crime in the United States, 1960–2010 [Dataset]. https://ucr.fbi.gov/
    • U.S. Environmental Protection Agency. (1996). EPA takes final step in phaseout of leaded gasoline. https://www.epa.gov/archive/epa/aboutepa/epa-takes-final-step-phaseout-leaded-gasoline.html
  2. Causal Framework:
    • Nevin, R. (2000). How lead exposure relates to temporal changes in IQ, violent crime, and unwed pregnancy. Environmental Research, 83(1), 1–22. https://doi.org/10.1006/enrs.1999.4045
    • Nevin, R. (2007). Understanding international crime trends: The legacy of preschool lead exposure. Environmental Research, 104(3), 315–336. https://doi.org/10.1016/j.envres.2007.02.008
    • Reyes, J. W. (2007). Environmental policy as social policy? The impact of childhood lead exposure on crime. The B.E. Journal of Economic Analysis & Policy, 7(1). https://doi.org/10.2202/1935-1682.1796

11. Custom Functions Documentation

Note📦 Custom Helper Functions

This analysis uses custom functions from my personal module library for efficiency and consistency across projects.

Functions Used:

  • fonts.R: setup_fonts(), get_font_families() - Font management with showtext
  • social_icons.R: create_social_caption() - Generates formatted social media captions
  • image_utils.R: save_plot() - Consistent plot saving with naming conventions
  • base_theme.R: create_base_theme(), extend_weekly_theme(), get_theme_colors() - Custom ggplot2 themes

Why custom functions?
These utilities standardize theming, fonts, and output across all my data visualizations. The core analysis (data tidying and visualization logic) uses only standard tidyverse packages.

Source Code:
View all custom functions → GitHub: R/utils

Back to top

Citation

BibTeX citation:
@online{ponce2026,
  author = {Ponce, Steven},
  title = {The {Crime} {Wave} {May} {Have} {Been} {Written} in 1970},
  date = {2026-04-16},
  url = {https://stevenponce.netlify.app/data_visualizations/30DayChartChallenge/2026/30dcc_2026_16.html},
  langid = {en}
}
For attribution, please cite this work as:
Ponce, Steven. 2026. “The Crime Wave May Have Been Written in 1970.” April 16, 2026. https://stevenponce.netlify.app/data_visualizations/30DayChartChallenge/2026/30dcc_2026_16.html.
Source Code
---
title: "The Crime Wave May Have Been Written in 1970"
subtitle: "Indexed U.S. trends in leaded gasoline use and violent crime rates</span>** reveal a ~22-year lag. Both series indexed to peak (= 100) to compare shape, not magnitude. Children exposed to lead in early life reach peak offending age ~20 years later."
description: "A dual-line chart exploring the lead-crime hypothesis: U.S. trends in leaded gasoline use and violent crime rates, indexed, reveal a striking ~22-year lag. Both series are normalized to their own peak (= 100) to compare shape and timing,   not magnitude. Built with ggplot2 in R as part of the #30DayChartChallenge 2026 —    Day 16: Causation."
date: "2026-04-16" 
author:
  - name: "Steven Ponce"
    url: "https://stevenponce.netlify.app"
citation:
  url: "https://stevenponce.netlify.app/data_visualizations/30DayChartChallenge/2026/30dcc_2026_16.html"
categories: ["30DayChartChallenge", "Data Visualization", "R Programming", "2026"]
tags: [
  "30DayChartChallenge",
  "Relationships",
  "Causation",
  "Lagged Causality",
  "Lead Crime Hypothesis",
  "Public Health",
  "Indexed Trends",
  "Dual Line Chart",
  "FBI UCR",
  "EPA",
  "Annotation",
  "ggplot2",
  "Time Series"
]
image: "thumbnails/30dcc_2026_16.png"
format:
  html:
    toc: true
    toc-depth: 5
    code-link: true
    code-fold: true
    code-tools: true
    code-summary: "Show code"
    self-contained: true
    theme: 
      light: [flatly, assets/styling/custom_styles.scss]
      dark: [darkly, assets/styling/custom_styles_dark.scss]
editor_options: 
  chunk_output_type: inline
execute: 
  freeze: true                                                  
  cache: true                                                   
  error: false
  message: false
  warning: false
  eval: true
---

![Line chart showing indexed U.S. trends in leaded gasoline use (red) and violent crime rates (dark) from 1941 to 2010, both normalized to peak = 100. Leaded gasoline peaked around 1970 and declined sharply after the EPA regulation began in 1973. Violent crime peaks around 1991 — approximately 22 years later — then falls steadily. A shaded band and arrow highlight the lag window between the two peaks, illustrating the hypothesis that early-life lead exposure shaped the U.S. crime wave two decades later.](30dcc_2026_16.png){#fig-1}

### [**Steps to Create this Graphic**]{.mark}

#### [1. Load Packages & Setup]{.smallcaps}

```{r}
#| label: load
#| warning: false
#| message: false      
#| results: "hide"     

## 1. LOAD PACKAGES & SETUP ----
suppressPackageStartupMessages({
pacman::p_load(
  tidyverse, ggtext, showtext,  
  janitor, scales, glue
  )
})

### |- figure size ----
camcorder::gg_record(
  dir    = here::here("temp_plots"),
  device = "png",
  width  = 12,
  height = 8,
  units  = "in",
  dpi    = 320
)

# Source utility functions
suppressMessages(source(here::here("R/utils/fonts.R")))
source(here::here("R/utils/social_icons.R"))
source(here::here("R/utils/image_utils.R"))
source(here::here("R/themes/base_theme.R"))
```

#### [2. Read in the Data]{.smallcaps}

```{r}
#| label: read
#| include: true
#| eval: true
#| warning: false

### |- leaded gasoline use (US, indexed: peak 1970 = 100) ----
### Values derived from Nevin (2000, 2007) Figure 1 data and EPA records.
### Units: thousands of short tons of lead emitted annually, normalized to peak.
### The series rises through the 1940s–60s as car ownership expands,
### peaks ~1970 at ~200,000 tons/year, then falls sharply after EPA phasedown
### begins 1973, accelerating in 1985 (90% reduction rule) and ban in 1996.

lead_raw <- tibble(
  year  = c(1941, 1945, 1950, 1955, 1960, 1963, 1965, 1967, 1969, 1970,
            1971, 1972, 1973, 1974, 1975, 1976, 1977, 1978, 1979, 1980,
            1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989, 1990,
            1991, 1992, 1993, 1994, 1995),
  lead  = c(  9,   11,   32,   52,   70,   80,   88,   93,   97,  100,
              99,   97,   94,   90,   83,   75,   68,   62,   57,   53,
              49,   43,   37,   30,   18,    9,    6,    5,    4,    3,
              2,    2,    1,    1,    1)
)

### |- FBI UCR violent crime rate per 100,000 (1960–2010) ----
### Source: FBI Uniform Crime Reporting Program.
### Violent crime = murder, rape (legacy def.), robbery, aggravated assault.
### Values rounded to nearest whole number from published FBI tables.
### Peak: ~758 per 100,000 in 1991.

crime_raw <- tibble(
  year  = c(1960, 1961, 1962, 1963, 1964, 1965, 1966, 1967, 1968, 1969,
            1970, 1971, 1972, 1973, 1974, 1975, 1976, 1977, 1978, 1979,
            1980, 1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989,
            1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
            2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
            2010),
  crime = c(161, 158, 162, 168, 190, 200, 220, 253, 298, 329,
            364, 396, 401, 417, 461, 482, 467, 476, 497, 549,
            597, 594, 571, 538, 539, 557, 617, 610, 640, 664,
            730, 758, 758, 747, 714, 685, 637, 611, 567, 524,
            507, 505, 494, 475, 463, 469, 474, 467, 455, 431,
            405)
)
```

#### [3. Examine the Data]{.smallcaps}

```{r}
#| label: examine
#| include: true
#| eval: true
#| results: 'hide'
#| warning: false

glimpse(lead_raw)
glimpse(crime_raw)

### Check peak years
lead_raw  |> slice_max(lead,  n = 3)   
crime_raw |> slice_max(crime, n = 3)  
```

#### [4. Tidy Data]{.smallcaps}

```{r}
#| label: tidy
#| warning: false

### |- Normalize each series: peak = 100 ----
lead_idx <- lead_raw |>
  mutate(
    index = lead / max(lead) * 100,
    series = "lead"
  )

crime_idx <- crime_raw |>
  mutate(
    index = crime / max(crime) * 100,
    series = "crime"
  )

### |- Combine for plotting ----
df_plot <- bind_rows(
  lead_idx |> select(year, index, series),
  crime_idx |> select(year, index, series)
) |>
  mutate(
    series = factor(series, levels = c("lead", "crime")),
    series_label = case_when(
      series == "lead" ~ "Leaded gasoline use",
      series == "crime" ~ "Violent crime rate"
    )
  )

### |- Annotation anchor points ----
lead_peak_year <- lead_raw |>
  slice_max(lead, n = 1) |>
  pull(year) # 1970
crime_peak_year <- crime_raw |>
  slice_max(crime, n = 1, with_ties = FALSE) |>
  pull(year) # 1991

lead_peak_idx <- 100
crime_peak_idx <- 100

### |- Key annotation coordinates ----
lag_xmin <- lead_peak_year # 1970
lag_xmax <- crime_peak_year # 1991
```


#### [5. Visualization Parameters]{.smallcaps}

```{r}
#| label: params
#| include: true
#| warning: false

### |- Plot aesthetics ----
colors <- get_theme_colors(
  palette = list(
    "lead"       = "#C0392B",  
    "crime"      = "#1C2833",  
    "lag_band"   = "#F0E6C8",  
    "annotation" = "#555555"   
  )
)

### |- Titles and caption ----
title_text <- "The Crime Wave May Have Been Written in 1970"

subtitle_text <- glue(
  "Indexed U.S. trends in **<span style='color:{colors$palette$lead}'>leaded gasoline use</span>** ",
  "and **<span style='color:{colors$palette$crime}'>violent crime rates</span>** ",
  "reveal a ~22-year lag.<br>",
  "Both series indexed to peak (= 100) to compare shape, not magnitude. ",
  "Children exposed to lead in early life reach peak offending age ~20 years later."
)

caption_text <- create_dcc_caption(
  dcc_year    = 2026,
  dcc_day     = 16,
  source_text = "FBI Uniform Crime Reporting Program; Nevin (2007) Environ. Res.; EPA lead phasedown records"
)

### |- Fonts ----
setup_fonts()
fonts <- get_font_families()

### |- base theme ----
base_theme <- create_base_theme(colors)

weekly_theme <- extend_weekly_theme(
  base_theme,
  theme(
    # Titles
    plot.title  = element_text(
      size = 26, face = "bold", family = fonts$title,
      color = colors$palette$crime, margin = margin(b = 6)
    ),
    plot.subtitle = element_markdown(
      size = 11, family = fonts$text,
      color = "#444444", lineheight = 1.4,
      margin = margin(b = 18)
    ),
    plot.caption  = element_markdown(
      size = 9, color = "gray50", hjust = 0,
      margin = margin(t = 14)
    ),
    
    # Axes
    axis.title.x = element_blank(),
    axis.title.y = element_text(
      size = 11, color = "gray45", family = fonts$text,
      margin = margin(r = 8), lineheight = 1.3
    ),
    axis.text = element_text(size = 10, color = "gray40", family = fonts$text),
    axis.ticks = element_blank(),
    
    # Grid — horizontal only, very light
    panel.grid.major.x = element_blank(),
    panel.grid.minor = element_blank(),
    panel.grid.major.y = element_line(color = "gray92", linewidth = 0.3),
    
    # Panel
    panel.background = element_rect(fill = "white", color = NA),
    plot.background = element_rect(fill = "white", color = NA),
    plot.margin = margin(20, 24, 12, 20)
  )
)

theme_set(weekly_theme)
```

#### [6. Plot]{.smallcaps}

```{r}
#| label: plot
#| warning: false

### |- main plot ----
p <- ggplot() +

  # Lag band
  annotate(
    "rect",
    xmin = lag_xmin, xmax = lag_xmax,
    ymin = -Inf, ymax = Inf,
    fill = colors$palette$lag_band, alpha = 0.35
  ) +

  # Geoms
  geom_line(
    data = df_plot |> filter(series == "lead"),
    aes(x = year, y = index),
    color = colors$palette$lead, linewidth = 1.1, lineend = "round"
  ) +
  geom_line(
    data = df_plot |> filter(series == "crime"),
    aes(x = year, y = index),
    color = colors$palette$crime, linewidth = 1.25, lineend = "round"
  ) +
  geom_point(
    data = tibble(year = lead_peak_year, index = lead_peak_idx, series = "lead"),
    aes(x = year, y = index),
    color = colors$palette$lead, size = 3.5
  ) +
  geom_point(
    data = tibble(year = crime_peak_year, index = crime_peak_idx, series = "crime"),
    aes(x = year, y = index),
    color = colors$palette$crime, size = 3.5
  ) +

  # Annotate
  annotate(
    "text",
    x = lead_peak_year - 1, y = lead_peak_idx + 5,
    label = "Lead peaks\n~1970",
    hjust = 1, vjust = 0, size = 4.1,
    color = colors$palette$lead, fontface = "bold"
  ) +
  annotate(
    "text",
    x = 1992, y = crime_peak_idx + 5,
    label = "Crime peaks\n~1991",
    hjust = 0, vjust = 0, size = 4.1,
    color = colors$palette$crime, fontface = "bold"
  ) +
  annotate(
    "segment",
    x = lag_xmin + 0.5, xend = lag_xmax - 0.5,
    y = 28, yend = 28,
    arrow = arrow(ends = "both", length = unit(0.12, "cm"), type = "closed"),
    color = "#8B6914", linewidth = 0.55
  ) +
  annotate(
    "text",
    x = (lag_xmin + lag_xmax) / 2, y = 36,
    label = "~22-year lag (exposure \u2192 peak offending age)",
    hjust = 0.5, size = 2.9,
    color = "#8B6914", fontface = "bold", family = "sans"
  ) +
  annotate(
    "segment",
    x = 1973, xend = 1973,
    y = 0, yend = 93,
    linetype = "dashed", color = "gray65", linewidth = 0.4
  ) +
  annotate(
    "text",
    x = 1972.2, y = 78,
    label = "EPA lead phaseout\nbegins (1973)",
    hjust = 1, size = 3.2, lineheight = 1.25,
    color = "gray35"
  ) +

  # Scales
  scale_x_continuous(
    breaks = seq(1945, 2010, by = 10),
    expand = expansion(mult = c(0.02, 0.02))
  ) +
  scale_y_continuous(
    limits = c(0, 115),
    breaks = seq(0, 100, by = 25),
    labels = function(x) ifelse(x == 100, "100\n(peak)", as.character(x)),
    expand = expansion(mult = c(0.01, 0.05))
  ) +
  # Labs
  labs(
    title    = title_text,
    subtitle = subtitle_text,
    caption  = caption_text,
    y        = "Index (peak = 100)"
  )
```

#### [7. Save]{.smallcaps}

```{r}
#| label: save
#| warning: false

### |-  plot image ----  
save_plot(
  p, 
  type = "30daychartchallenge", 
  year = 2026, 
  day = 16, 
  width = 12, 
  height = 8
  )
```

#### [8. Session Info]{.smallcaps}

::: {.callout-tip collapse="true"}
##### Expand for Session Info

```{r, echo = FALSE}
#| eval: true
#| warning: false

sessionInfo()
```
:::

#### [9. GitHub Repository]{.smallcaps} 

::: {.callout-tip collapse="true"}
##### Expand for GitHub Repo

The complete code for this analysis is available in [`30dcc_2026_16.qmd`](https://github.com/poncest/personal-website/blob/master/data_visualizations/TidyTuesday/2026/30dcc_2026_16.qmd).

For the full repository, [click here](https://github.com/poncest/personal-website/).
:::


#### [10. References]{.smallcaps}
::: {.callout-tip collapse="true"}
##### Expand for References

1. **Data Sources:**
   - Federal Bureau of Investigation. *Uniform Crime Reporting (UCR) Program — Crime in the United States, 1960–2010* [Dataset]. https://ucr.fbi.gov/
   - U.S. Environmental Protection Agency. (1996). *EPA takes final step in phaseout of leaded gasoline*. https://www.epa.gov/archive/epa/aboutepa/epa-takes-final-step-phaseout-leaded-gasoline.html

2. **Causal Framework:**
   - Nevin, R. (2000). How lead exposure relates to temporal changes in IQ, violent crime, and unwed pregnancy. *Environmental Research, 83*(1), 1–22. https://doi.org/10.1006/enrs.1999.4045
   - Nevin, R. (2007). Understanding international crime trends: The legacy of preschool lead exposure. *Environmental Research, 104*(3), 315–336. https://doi.org/10.1016/j.envres.2007.02.008
   - Reyes, J. W. (2007). Environmental policy as social policy? The impact of childhood lead exposure on crime. *The B.E. Journal of Economic Analysis & Policy, 7*(1). https://doi.org/10.2202/1935-1682.1796

:::


#### [11. Custom Functions Documentation]{.smallcaps}

::: {.callout-note collapse="true"}
##### 📦 Custom Helper Functions

This analysis uses custom functions from my personal module library for efficiency and consistency across projects.

**Functions Used:**

-   **`fonts.R`**: `setup_fonts()`, `get_font_families()` - Font management with showtext
-   **`social_icons.R`**: `create_social_caption()` - Generates formatted social media captions
-   **`image_utils.R`**: `save_plot()` - Consistent plot saving with naming conventions
-   **`base_theme.R`**: `create_base_theme()`, `extend_weekly_theme()`, `get_theme_colors()` - Custom ggplot2 themes

**Why custom functions?**\
These utilities standardize theming, fonts, and output across all my data visualizations. The core analysis (data tidying and visualization logic) uses only standard tidyverse packages.

**Source Code:**\
View all custom functions → [GitHub: R/utils](https://github.com/poncest/personal-website/tree/master/R)
:::

© 2024 Steven Ponce

Source Issues