• 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

As child mortality falls, risk concentrates at birth

  • Show All Code
  • Hide All Code

  • View Source

Regional mortality rates declined sharply from 1990 to 2023, but neonatal deaths fell less than under-five deaths — shifting risk toward the earliest days of life. Each dumbbell shows the change from 1990 (open circle) to 2023 (filled) by region. Rates per 1,000 live births.

30DayChartChallenge
Data Visualization
R Programming
2026
Regional child mortality rates declined sharply from 1990 to 2023, but neonatal deaths fell more slowly than under-five deaths — shifting risk toward the earliest days of life. This dumbbell chart visualizes that divergence across four world regions using UNICEF Child Mortality Estimates 2024, built with ggplot2 and patchwork in R.
Author

Steven Ponce

Published

April 18, 2026

Figure 1: A dumbbell chart comparing under-five and neonatal mortality rates across four regions (Sub-Saharan Africa, World, South Asia, Latin America & Caribbean) between 1990 (open circle) and 2023 (filled circle). Both panels show sharp declines, but the neonatal panel reveals slower progress — illustrated by shorter dumbbells relative to starting values. A callout notes that neonatal deaths rose from 39% to 47% of all under-five deaths globally between 1990 and 2023, signaling a concentration of child mortality risk in the first 28 days of life. Rates are per 1,000 live births.

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, camcorder, readxl, here, patchwork
  )
})

### |- figure size ----
camcorder::gg_record(
  dir    = here::here("temp_plots"),
  device = "png",
  width  = 10,
  height = 7,
  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

path_u5mr <- here("data", "30DayChartChallenge", "2026", "Under-five_Mortality_Rates_2024.xlsx")
path_nmr  <- here("data", "30DayChartChallenge", "2026", "Neonatal_Mortality_Rates_2024.xlsx")

# Helper: read one regional sheet from an IGME xlsx and return a long tibble
read_igme_sheet <- function(path, sheet, indicator_label, skip = 15) {
  read_excel(path, sheet = sheet, skip = skip) |>
    clean_names() |>
    filter(uncertainty_bounds == "Median") |>
    select(region_name, starts_with("x")) |>
    pivot_longer(
      cols      = starts_with("x"),
      names_to  = "year_raw",
      values_to = "rate"
    ) |>
    mutate(
      year      = as.integer(str_extract(year_raw, "\\d{4}")),
      rate      = as.numeric(rate),
      indicator = indicator_label
    ) |>
    filter(!is.na(rate), year >= 1990, year <= 2023) |>
    select(region_name, year, rate, indicator) |>
    distinct(region_name, year, indicator, .keep_all = TRUE)
}

df_u5mr <- read_igme_sheet(path_u5mr, "U5MR Regional estimates", "Under-Five (U5MR)")
df_nmr <- read_igme_sheet(path_nmr, "NMR Regional estimates", "Neonatal (NMR)")

df_all <- bind_rows(df_u5mr, df_nmr)
```

3. Examine the Data

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

glimpse(df_all)
df_all |> distinct(region_name) |> arrange(region_name) |> print(n = 30)
df_all |> filter(year %in% c(1990, 2023)) |> arrange(indicator, region_name, year)
```

4. Tidy Data

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

# Regions to include — one global anchor + four regional contrasts
regions_keep <- c(
  "World",
  "Sub-Saharan Africa",
  "South Asia",
  "Latin America and the Caribbean",
  "East Asia and the Pacific"
)

# Dumbbell endpoints: 1990 and 2023
df_dumbbell <- df_all |>
  filter(
    region_name %in% regions_keep,
    year %in% c(1990, 2023)
  ) |>
  mutate(
    year_label = if_else(year == 1990, "y1990", "y2023"),
    # Short region names for axis labels
    region_short = case_when(
      region_name == "World" ~ "World",
      region_name == "Sub-Saharan Africa" ~ "Sub-Saharan\nAfrica",
      region_name == "South Asia" ~ "South Asia",
      str_detect(region_name, "Latin America") ~ "Latin America\n& Caribbean",
      str_detect(region_name, "East Asia") ~ "East Asia\n& Pacific",
      TRUE ~ region_name
    )
  ) |>
  pivot_wider(
    id_cols = c(region_name, region_short, indicator),
    names_from = year_label,
    values_from = rate
  ) |>
  mutate(
    decline_abs  = y1990 - y2023,
    decline_pct  = (y1990 - y2023) / y1990
  )

# Sort order
region_order <- df_dumbbell |>
  filter(indicator == "Under-Five (U5MR)") |>
  arrange(y2023) |>
  pull(region_short)

df_dumbbell <- df_dumbbell |>
  mutate(region_short = factor(region_short, levels = region_order))

# Neonatal share annotation
nmr_world_2023 <- df_dumbbell |>
  filter(indicator == "Neonatal (NMR)", region_name == "World") |>
  pull(y2023)

u5mr_world_2023 <- df_dumbbell |>
  filter(indicator == "Under-Five (U5MR)", region_name == "World") |>
  pull(y2023)

nmr_share_2023 <- round(nmr_world_2023 / u5mr_world_2023 * 100)

nmr_world_1990 <- df_dumbbell |>
  filter(indicator == "Neonatal (NMR)", region_name == "World") |>
  pull(y1990)

u5mr_world_1990 <- df_dumbbell |>
  filter(indicator == "Under-Five (U5MR)", region_name == "World") |>
  pull(y1990)

nmr_share_1990 <- round(nmr_world_1990 / u5mr_world_1990 * 100)
```

5. Visualization Parameters

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

### |- plot aesthetics ----
colors <- get_theme_colors(palette = list(
  "u5mr"    = "#4a90b8",   
  "nmr"     = "#1a3a5c",   
  "segment" = "#d0dde6",  
  "dot_1990"= "#7a9bb5",  
  "text"    = "#1e2d3d",
  "subtle"  = "#7a8a99"
))

col_u5mr     <- colors$palette$u5mr
col_nmr      <- colors$palette$nmr
col_segment  <- colors$palette$segment
col_dot_1990 <- colors$palette$dot_1990
col_text     <- colors$palette$text
col_subtle   <- colors$palette$subtle

### |- titles and caption ----
title_text    <- "As child mortality falls, risk concentrates at birth"

subtitle_text <- paste0(
  "Regional mortality rates declined sharply from 1990 to 2023, but neonatal deaths fell ",
  "less than under-five deaths — shifting risk toward the earliest days of life.<br>",
  "Each dumbbell shows the change from ",
  "<span style='color:", col_dot_1990, "; font-weight:600'>1990 (open circle)</span>",
  " to ",
  "<span style='color:", col_nmr, "; font-weight:600'>2023 (filled)</span>",
  " by region. Rates per 1,000 live births."
)

caption_text <- create_dcc_caption(
  dcc_year    = 2026,
  dcc_day     = 18,
  source_text = "UN IGME via UNICEF · Child Mortality Estimates 2024 (data.unicef.org)"
)

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

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

weekly_theme <- extend_weekly_theme(
  base_theme,
  theme(
    axis.ticks = element_blank(),
    axis.line = element_blank(),
    panel.grid.major.x = element_line(color = "gray93", linewidth = 0.3),
    panel.grid.major.y = element_blank(),
    panel.grid.minor = element_blank(),
    plot.title = element_text(
      family = fonts$title, face = "bold", size = 20,
      color = col_text, margin = margin(b = 6)
    ),
    plot.subtitle = element_markdown(
      family = 'sans', size = 10, color = "#4a5568",
      margin = margin(b = 16), lineheight = 1.4
    ),
    plot.caption = element_markdown(
      family = fonts$text, size = 7.5, color = col_subtle,
      margin = margin(t = 12), hjust = 0
    ),
    legend.position = "none",
    plot.margin = margin(16, 16, 10, 16)
  )
)

theme_set(weekly_theme)
```

6. Plot

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

### |- dumbbell builder function ----
build_dumbbell_panel <- function(data, indicator_name, col_2023, panel_title, panel_subtitle) {
  d <- data |> filter(indicator == indicator_name)

  ggplot(d, aes(y = region_short)) +

    # Connector segment (1990 → 2023)
    geom_segment(
      aes(x = y2023, xend = y1990, yend = region_short),
      color = col_segment,
      linewidth = 1.8,
      lineend = "round"
    ) +

    # 1990 endpoint (muted)
    geom_point(
      aes(x = y1990),
      color = col_dot_1990,
      size = 3.5,
      shape = 21,
      fill = "white",
      stroke = 1.2
    ) +

    # 2023 endpoint (accent)
    geom_point(
      aes(x = y2023),
      color = col_2023,
      size = 4.5,
      shape = 21,
      fill = col_2023,
      stroke = 0
    ) +

    # 2023 rate label (right of dot)
    geom_text(
      aes(x = y2023, label = round(y2023, 1)),
      hjust = -0.5,
      size = 2.8,
      color = col_text,
      family = fonts$text
    ) +
    labs(
      title = panel_title,
      subtitle = panel_subtitle,
      x = NULL, y = NULL
    ) +
    theme(
      plot.title = element_text(
        family = fonts$title, face = "bold", size = 11,
        color = col_2023, margin = margin(b = 2)
      ),
      plot.subtitle = element_markdown(
        family = 'sans', size = 8.5, color = col_subtle,
        margin = margin(b = 10), lineheight = 1.3
      ),
      axis.text.y = element_text(
        family = fonts$text, size = 8.5, color = col_text,
        lineheight = 1.2
      ),
      axis.text.x = element_text(
        family = fonts$text, size = 7.5, color = col_subtle
      ),
      panel.grid.major.x = element_line(color = "gray93", linewidth = 0.3),
      panel.grid.major.y = element_blank(),
      panel.grid.minor = element_blank(),
      plot.margin = margin(8, 24, 8, 8)
    )
}

### |- individual plots ----
p_u5mr <- build_dumbbell_panel(
  data           = df_dumbbell,
  indicator_name = "Under-Five (U5MR)",
  col_2023       = col_u5mr,
  panel_title    = "Under-Five Mortality Rate",
  panel_subtitle = "Deaths per 1,000 live births, children under age 5"
)

p_nmr <- build_dumbbell_panel(
  data           = df_dumbbell,
  indicator_name = "Neonatal (NMR)",
  col_2023       = col_nmr,
  panel_title    = "Neonatal Mortality Rate",
  panel_subtitle = "Deaths per 1,000 live births, first 28 days of life"
) +

  annotate(
    "text",
    x = Inf, y = -Inf,
    label = glue::glue(
      "Globally, neonatal deaths rose from {nmr_share_1990}% to {nmr_share_2023}%\n",
      "of all under-five deaths (1990 to 2023)"
    ),
    hjust = 1.05, vjust = -0.6,
    size = 3.0, color = col_nmr,
    family = fonts$text,
    lineheight = 1.3,
    fontface = "italic"
  )

### |- combined plots ----
p <- (p_u5mr | p_nmr) +
  plot_annotation(
    title = title_text,
    subtitle = subtitle_text,
    caption = caption_text,
    theme = theme(
      plot.title = element_text(
        family = fonts$title, face = "bold", size = 26,
        color = col_text, margin = margin(b = 6)
      ),
      plot.subtitle = element_markdown(
        family = 'sans', size = 8, color = "#4a5568",
        margin = margin(b = 4), lineheight = 1.4
      ),
      plot.caption = element_markdown(
        family = fonts$text, size = 6.5, color = col_subtle,
        margin = margin(t = 10), hjust = 0
      ),
      plot.margin = margin(16, 16, 10, 16)
    )
  )
```

7. Save

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

### |-  plot image ----  
save_plot_patchwork(
  p, 
  type = "30daychartchallenge", 
  year = 2026, 
  day = 18, 
  width = 10, 
  height = 7
  )
```

8. Session Info

TipExpand for Session Info
R version 4.5.3 (2026-03-11 ucrt)
Platform: x86_64-w64-mingw32/x64
Running under: Windows 11 x64 (build 26100)

Matrix products: default
  LAPACK version 3.12.1

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] patchwork_1.3.2 here_1.0.2      readxl_1.4.5    camcorder_0.1.0
 [5] glue_1.8.0      scales_1.4.0    janitor_2.2.1   showtext_0.9-8 
 [9] showtextdb_3.0  sysfonts_0.8.9  ggtext_0.1.2    lubridate_1.9.5
[13] forcats_1.0.1   stringr_1.6.0   dplyr_1.2.1     purrr_1.2.2    
[17] readr_2.2.0     tidyr_1.3.2     tibble_3.3.1    ggplot2_4.0.2  
[21] tidyverse_2.0.0

loaded via a namespace (and not attached):
 [1] gtable_0.3.6       xfun_0.57          htmlwidgets_1.6.4  tzdb_0.5.0        
 [5] yulab.utils_0.2.4  vctrs_0.7.3        tools_4.5.3        generics_0.1.4    
 [9] curl_7.0.0         gifski_1.32.0-2    pacman_0.5.1       pkgconfig_2.0.3   
[13] ggplotify_0.1.3    RColorBrewer_1.1-3 S7_0.2.1           lifecycle_1.0.5   
[17] compiler_4.5.3     farver_2.1.2       textshaping_1.0.5  codetools_0.2-20  
[21] snakecase_0.11.1   litedown_0.9       htmltools_0.5.9    yaml_2.3.12       
[25] pillar_1.11.1      magick_2.9.1       commonmark_2.0.0   tidyselect_1.2.1  
[29] digest_0.6.39      stringi_1.8.7      labeling_0.4.3     rsvg_2.7.0        
[33] rprojroot_2.1.1    fastmap_1.2.0      grid_4.5.3         cli_3.6.6         
[37] magrittr_2.0.5     utf8_1.2.6         withr_3.0.2        rappdirs_0.3.4    
[41] timechange_0.4.0   rmarkdown_2.31     otel_0.2.0         cellranger_1.1.0  
[45] hms_1.1.4          evaluate_1.0.5     knitr_1.51         markdown_2.0      
[49] gridGraphics_0.5-1 rlang_1.2.0        gridtext_0.1.6     Rcpp_1.1.1        
[53] xml2_1.5.2         svglite_2.2.2      rstudioapi_0.18.0  jsonlite_2.0.0    
[57] R6_2.6.1           fs_2.0.1           systemfonts_1.3.2 

9. GitHub Repository

TipExpand for GitHub Repo

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

For the full repository, click here.

10. References

TipExpand for References
  1. Data Sources:
    • UN Inter-agency Group for Child Mortality Estimation (UN IGME) via UNICEF. Child Mortality Estimates 2024 [Dataset]. https://data.unicef.org/resources/dataset/child-mortality/
      • Under-five_Mortality_Rates_2024.xlsx — sheet: “U5MR Regional estimates”
      • Neonatal_Mortality_Rates_2024.xlsx — sheet: “NMR Regional estimates” Last updated: March 2025 | License: CC BY 3.0 IGO

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 = {As Child Mortality Falls, Risk Concentrates at Birth},
  date = {2026-04-18},
  url = {https://stevenponce.netlify.app/data_visualizations/30DayChartChallenge/2026/30dcc_2026_18.html},
  langid = {en}
}
For attribution, please cite this work as:
Ponce, Steven. 2026. “As Child Mortality Falls, Risk Concentrates at Birth.” April 18, 2026. https://stevenponce.netlify.app/data_visualizations/30DayChartChallenge/2026/30dcc_2026_18.html.
Source Code
---
title: "As child mortality falls, risk concentrates at birth"
subtitle: "Regional mortality rates declined sharply from 1990 to 2023, but neonatal deaths fell less than under-five deaths — shifting risk toward the earliest days of life. Each dumbbell shows the change from 1990 (open circle) to 2023 (filled) by region. Rates per 1,000 live births."
description: "Regional child mortality rates declined sharply from 1990 to 2023, but neonatal deaths fell more slowly than under-five deaths — shifting risk toward the earliest days of life. This dumbbell chart visualizes that divergence across four world regions using UNICEF Child Mortality Estimates 2024, built with ggplot2 and patchwork in R."
date: "2026-04-18" 
author:
  - name: "Steven Ponce"
    url: "https://stevenponce.netlify.app"
citation:
  url: "https://stevenponce.netlify.app/data_visualizations/30DayChartChallenge/2026/30dcc_2026_18.html"
categories: ["30DayChartChallenge", "Data Visualization", "R Programming", "2026"]
tags: [
  "30DayChartChallenge",
  "Relationships",
  "UNICEF",
  "Child Mortality",
  "Neonatal Mortality",
  "Dumbbell Chart",
  "Public Health",
  "Global Health",
  "ggplot2",
  "patchwork",
  "R Programming",
  "Data Journalism"
]
image: "thumbnails/30dcc_2026_18.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
---

![A dumbbell chart comparing under-five and neonatal mortality rates across four regions (Sub-Saharan Africa, World, South Asia, Latin America & Caribbean) between 1990 (open circle) and 2023 (filled circle). Both panels show sharp declines, but the neonatal panel reveals slower progress — illustrated by shorter dumbbells relative to starting values. A callout notes that neonatal deaths rose from 39% to 47% of all under-five deaths globally between 1990 and 2023, signaling a concentration of child mortality risk in the first 28 days of life. Rates are per 1,000 live births.](30dcc_2026_18.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, camcorder, readxl, here, patchwork
  )
})

### |- figure size ----
camcorder::gg_record(
  dir    = here::here("temp_plots"),
  device = "png",
  width  = 10,
  height = 7,
  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

path_u5mr <- here("data", "30DayChartChallenge", "2026", "Under-five_Mortality_Rates_2024.xlsx")
path_nmr  <- here("data", "30DayChartChallenge", "2026", "Neonatal_Mortality_Rates_2024.xlsx")

# Helper: read one regional sheet from an IGME xlsx and return a long tibble
read_igme_sheet <- function(path, sheet, indicator_label, skip = 15) {
  read_excel(path, sheet = sheet, skip = skip) |>
    clean_names() |>
    filter(uncertainty_bounds == "Median") |>
    select(region_name, starts_with("x")) |>
    pivot_longer(
      cols      = starts_with("x"),
      names_to  = "year_raw",
      values_to = "rate"
    ) |>
    mutate(
      year      = as.integer(str_extract(year_raw, "\\d{4}")),
      rate      = as.numeric(rate),
      indicator = indicator_label
    ) |>
    filter(!is.na(rate), year >= 1990, year <= 2023) |>
    select(region_name, year, rate, indicator) |>
    distinct(region_name, year, indicator, .keep_all = TRUE)
}

df_u5mr <- read_igme_sheet(path_u5mr, "U5MR Regional estimates", "Under-Five (U5MR)")
df_nmr <- read_igme_sheet(path_nmr, "NMR Regional estimates", "Neonatal (NMR)")

df_all <- bind_rows(df_u5mr, df_nmr)
```

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

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

glimpse(df_all)
df_all |> distinct(region_name) |> arrange(region_name) |> print(n = 30)
df_all |> filter(year %in% c(1990, 2023)) |> arrange(indicator, region_name, year)
```

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

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

# Regions to include — one global anchor + four regional contrasts
regions_keep <- c(
  "World",
  "Sub-Saharan Africa",
  "South Asia",
  "Latin America and the Caribbean",
  "East Asia and the Pacific"
)

# Dumbbell endpoints: 1990 and 2023
df_dumbbell <- df_all |>
  filter(
    region_name %in% regions_keep,
    year %in% c(1990, 2023)
  ) |>
  mutate(
    year_label = if_else(year == 1990, "y1990", "y2023"),
    # Short region names for axis labels
    region_short = case_when(
      region_name == "World" ~ "World",
      region_name == "Sub-Saharan Africa" ~ "Sub-Saharan\nAfrica",
      region_name == "South Asia" ~ "South Asia",
      str_detect(region_name, "Latin America") ~ "Latin America\n& Caribbean",
      str_detect(region_name, "East Asia") ~ "East Asia\n& Pacific",
      TRUE ~ region_name
    )
  ) |>
  pivot_wider(
    id_cols = c(region_name, region_short, indicator),
    names_from = year_label,
    values_from = rate
  ) |>
  mutate(
    decline_abs  = y1990 - y2023,
    decline_pct  = (y1990 - y2023) / y1990
  )

# Sort order
region_order <- df_dumbbell |>
  filter(indicator == "Under-Five (U5MR)") |>
  arrange(y2023) |>
  pull(region_short)

df_dumbbell <- df_dumbbell |>
  mutate(region_short = factor(region_short, levels = region_order))

# Neonatal share annotation
nmr_world_2023 <- df_dumbbell |>
  filter(indicator == "Neonatal (NMR)", region_name == "World") |>
  pull(y2023)

u5mr_world_2023 <- df_dumbbell |>
  filter(indicator == "Under-Five (U5MR)", region_name == "World") |>
  pull(y2023)

nmr_share_2023 <- round(nmr_world_2023 / u5mr_world_2023 * 100)

nmr_world_1990 <- df_dumbbell |>
  filter(indicator == "Neonatal (NMR)", region_name == "World") |>
  pull(y1990)

u5mr_world_1990 <- df_dumbbell |>
  filter(indicator == "Under-Five (U5MR)", region_name == "World") |>
  pull(y1990)

nmr_share_1990 <- round(nmr_world_1990 / u5mr_world_1990 * 100)
```


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

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

### |- plot aesthetics ----
colors <- get_theme_colors(palette = list(
  "u5mr"    = "#4a90b8",   
  "nmr"     = "#1a3a5c",   
  "segment" = "#d0dde6",  
  "dot_1990"= "#7a9bb5",  
  "text"    = "#1e2d3d",
  "subtle"  = "#7a8a99"
))

col_u5mr     <- colors$palette$u5mr
col_nmr      <- colors$palette$nmr
col_segment  <- colors$palette$segment
col_dot_1990 <- colors$palette$dot_1990
col_text     <- colors$palette$text
col_subtle   <- colors$palette$subtle

### |- titles and caption ----
title_text    <- "As child mortality falls, risk concentrates at birth"

subtitle_text <- paste0(
  "Regional mortality rates declined sharply from 1990 to 2023, but neonatal deaths fell ",
  "less than under-five deaths — shifting risk toward the earliest days of life.<br>",
  "Each dumbbell shows the change from ",
  "<span style='color:", col_dot_1990, "; font-weight:600'>1990 (open circle)</span>",
  " to ",
  "<span style='color:", col_nmr, "; font-weight:600'>2023 (filled)</span>",
  " by region. Rates per 1,000 live births."
)

caption_text <- create_dcc_caption(
  dcc_year    = 2026,
  dcc_day     = 18,
  source_text = "UN IGME via UNICEF · Child Mortality Estimates 2024 (data.unicef.org)"
)

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

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

weekly_theme <- extend_weekly_theme(
  base_theme,
  theme(
    axis.ticks = element_blank(),
    axis.line = element_blank(),
    panel.grid.major.x = element_line(color = "gray93", linewidth = 0.3),
    panel.grid.major.y = element_blank(),
    panel.grid.minor = element_blank(),
    plot.title = element_text(
      family = fonts$title, face = "bold", size = 20,
      color = col_text, margin = margin(b = 6)
    ),
    plot.subtitle = element_markdown(
      family = 'sans', size = 10, color = "#4a5568",
      margin = margin(b = 16), lineheight = 1.4
    ),
    plot.caption = element_markdown(
      family = fonts$text, size = 7.5, color = col_subtle,
      margin = margin(t = 12), hjust = 0
    ),
    legend.position = "none",
    plot.margin = margin(16, 16, 10, 16)
  )
)

theme_set(weekly_theme)
```

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

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

### |- dumbbell builder function ----
build_dumbbell_panel <- function(data, indicator_name, col_2023, panel_title, panel_subtitle) {
  d <- data |> filter(indicator == indicator_name)

  ggplot(d, aes(y = region_short)) +

    # Connector segment (1990 → 2023)
    geom_segment(
      aes(x = y2023, xend = y1990, yend = region_short),
      color = col_segment,
      linewidth = 1.8,
      lineend = "round"
    ) +

    # 1990 endpoint (muted)
    geom_point(
      aes(x = y1990),
      color = col_dot_1990,
      size = 3.5,
      shape = 21,
      fill = "white",
      stroke = 1.2
    ) +

    # 2023 endpoint (accent)
    geom_point(
      aes(x = y2023),
      color = col_2023,
      size = 4.5,
      shape = 21,
      fill = col_2023,
      stroke = 0
    ) +

    # 2023 rate label (right of dot)
    geom_text(
      aes(x = y2023, label = round(y2023, 1)),
      hjust = -0.5,
      size = 2.8,
      color = col_text,
      family = fonts$text
    ) +
    labs(
      title = panel_title,
      subtitle = panel_subtitle,
      x = NULL, y = NULL
    ) +
    theme(
      plot.title = element_text(
        family = fonts$title, face = "bold", size = 11,
        color = col_2023, margin = margin(b = 2)
      ),
      plot.subtitle = element_markdown(
        family = 'sans', size = 8.5, color = col_subtle,
        margin = margin(b = 10), lineheight = 1.3
      ),
      axis.text.y = element_text(
        family = fonts$text, size = 8.5, color = col_text,
        lineheight = 1.2
      ),
      axis.text.x = element_text(
        family = fonts$text, size = 7.5, color = col_subtle
      ),
      panel.grid.major.x = element_line(color = "gray93", linewidth = 0.3),
      panel.grid.major.y = element_blank(),
      panel.grid.minor = element_blank(),
      plot.margin = margin(8, 24, 8, 8)
    )
}

### |- individual plots ----
p_u5mr <- build_dumbbell_panel(
  data           = df_dumbbell,
  indicator_name = "Under-Five (U5MR)",
  col_2023       = col_u5mr,
  panel_title    = "Under-Five Mortality Rate",
  panel_subtitle = "Deaths per 1,000 live births, children under age 5"
)

p_nmr <- build_dumbbell_panel(
  data           = df_dumbbell,
  indicator_name = "Neonatal (NMR)",
  col_2023       = col_nmr,
  panel_title    = "Neonatal Mortality Rate",
  panel_subtitle = "Deaths per 1,000 live births, first 28 days of life"
) +

  annotate(
    "text",
    x = Inf, y = -Inf,
    label = glue::glue(
      "Globally, neonatal deaths rose from {nmr_share_1990}% to {nmr_share_2023}%\n",
      "of all under-five deaths (1990 to 2023)"
    ),
    hjust = 1.05, vjust = -0.6,
    size = 3.0, color = col_nmr,
    family = fonts$text,
    lineheight = 1.3,
    fontface = "italic"
  )

### |- combined plots ----
p <- (p_u5mr | p_nmr) +
  plot_annotation(
    title = title_text,
    subtitle = subtitle_text,
    caption = caption_text,
    theme = theme(
      plot.title = element_text(
        family = fonts$title, face = "bold", size = 26,
        color = col_text, margin = margin(b = 6)
      ),
      plot.subtitle = element_markdown(
        family = 'sans', size = 8, color = "#4a5568",
        margin = margin(b = 4), lineheight = 1.4
      ),
      plot.caption = element_markdown(
        family = fonts$text, size = 6.5, color = col_subtle,
        margin = margin(t = 10), hjust = 0
      ),
      plot.margin = margin(16, 16, 10, 16)
    )
  )
```

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

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

### |-  plot image ----  
save_plot_patchwork(
  p, 
  type = "30daychartchallenge", 
  year = 2026, 
  day = 18, 
  width = 10, 
  height = 7
  )
```

#### [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_18.qmd`](https://github.com/poncest/personal-website/blob/master/data_visualizations/TidyTuesday/2026/30dcc_2026_18.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:**
   - UN Inter-agency Group for Child Mortality Estimation (UN IGME) via UNICEF.
     *Child Mortality Estimates 2024* [Dataset].
     https://data.unicef.org/resources/dataset/child-mortality/
     - Under-five_Mortality_Rates_2024.xlsx — sheet: "U5MR Regional estimates"
     - Neonatal_Mortality_Rates_2024.xlsx — sheet: "NMR Regional estimates"
     Last updated: March 2025 | License: CC BY 3.0 IGO
:::


#### [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