• 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

Global Trade Connects Regions Through a Few Dominant Product Flows

  • Show All Code
  • Hide All Code

  • View Source

Average annual exports by region and product group (2019–2023)

30DayChartChallenge
Data Visualization
R Programming
2026
An alluvial chart mapping average merchandise exports (2019–2023) from five world regions to three product groups — Agriculture, Fuels & Mining, and Manufactures. Built with ggalluvial in R, the chart reveals that manufactured goods dominate export flows across every region, with Asia and Europe leading in volume. Day 14 of the #30DayChartChallenge 2026.
Author

Steven Ponce

Published

April 14, 2026

Figure 1: An alluvial (Sankey-style) chart titled “Global Trade Connects Regions Through a Few Dominant Product Flows.” The left axis shows five world regions — Asia, Europe, the Americas, Africa, and Oceania — ordered from the largest to the smallest exporter. Flows connect each region to one of three product groups on the right: Agriculture (green), Fuels & Mining (copper), and Manufacturing (burgundy). Asia and Europe generate the widest flows, with manufactured goods — shown in deep burgundy — dominating exports across every region. Fuels & Mining flows are most prominent from the Americas and Africa. Agriculture flows are thin across all regions. Data represent average annual merchandise exports from 2019 to 2023, sourced from the WTO Statistics Portal.

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, ggalluvial
  )
})

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

wto_raw <- read_csv(
  here::here("data/30DayChartChallenge/2026/wto_merchandise_values_annual_dataset.csv"),
  locale = locale(encoding = "latin1")
  ) |>
  clean_names() 
```

3. Examine the Data

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

glimpse(wto_raw)
```

4. Tidy Data

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

### |- OWID continent lookup ----
owid_regions <- tribble(
  ~iso3,  ~region,
  # Africa
  "DZA", "Africa", "AGO", "Africa", "BEN", "Africa", "BWA", "Africa",
  "BFA", "Africa", "BDI", "Africa", "CPV", "Africa", "CMR", "Africa",
  "CAF", "Africa", "TCD", "Africa", "COM", "Africa", "COD", "Africa",
  "COG", "Africa", "CIV", "Africa", "DJI", "Africa", "EGY", "Africa",
  "GNQ", "Africa", "ERI", "Africa", "SWZ", "Africa", "ETH", "Africa",
  "GAB", "Africa", "GMB", "Africa", "GHA", "Africa", "GIN", "Africa",
  "GNB", "Africa", "KEN", "Africa", "LSO", "Africa", "LBR", "Africa",
  "LBY", "Africa", "MDG", "Africa", "MWI", "Africa", "MLI", "Africa",
  "MRT", "Africa", "MUS", "Africa", "MAR", "Africa", "MOZ", "Africa",
  "NAM", "Africa", "NER", "Africa", "NGA", "Africa", "RWA", "Africa",
  "STP", "Africa", "SEN", "Africa", "SLE", "Africa", "SOM", "Africa",
  "ZAF", "Africa", "SSD", "Africa", "SDN", "Africa", "TZA", "Africa",
  "TGO", "Africa", "TUN", "Africa", "UGA", "Africa", "ZMB", "Africa",
  "ZWE", "Africa",
  # Americas
  "ARG", "Americas", "BHS", "Americas", "BRB", "Americas", "BLZ", "Americas",
  "BOL", "Americas", "BRA", "Americas", "CAN", "Americas", "CHL", "Americas",
  "COL", "Americas", "CRI", "Americas", "CUB", "Americas", "DOM", "Americas",
  "ECU", "Americas", "SLV", "Americas", "GTM", "Americas", "GUY", "Americas",
  "HTI", "Americas", "HND", "Americas", "JAM", "Americas", "MEX", "Americas",
  "NIC", "Americas", "PAN", "Americas", "PRY", "Americas", "PER", "Americas",
  "TTO", "Americas", "USA", "Americas", "URY", "Americas", "VEN", "Americas",
  # Asia
  "AFG", "Asia", "ARM", "Asia", "AZE", "Asia", "BGD", "Asia",
  "BTN", "Asia", "BRN", "Asia", "KHM", "Asia", "CHN", "Asia",
  "GEO", "Asia", "IND", "Asia", "IDN", "Asia", "IRN", "Asia",
  "IRQ", "Asia", "ISR", "Asia", "JPN", "Asia", "JOR", "Asia",
  "KAZ", "Asia", "PRK", "Asia", "KOR", "Asia", "KWT", "Asia",
  "KGZ", "Asia", "LAO", "Asia", "LBN", "Asia", "MYS", "Asia",
  "MDV", "Asia", "MNG", "Asia", "MMR", "Asia", "NPL", "Asia",
  "OMN", "Asia", "PAK", "Asia", "PSE", "Asia", "PHL", "Asia",
  "QAT", "Asia", "SAU", "Asia", "SGP", "Asia", "LKA", "Asia",
  "SYR", "Asia", "TWN", "Asia", "TJK", "Asia", "THA", "Asia",
  "TLS", "Asia", "TKM", "Asia", "ARE", "Asia", "UZB", "Asia",
  "VNM", "Asia", "YEM", "Asia",
  # Europe
  "ALB", "Europe", "AND", "Europe", "AUT", "Europe", "BLR", "Europe",
  "BEL", "Europe", "BIH", "Europe", "BGR", "Europe", "HRV", "Europe",
  "CYP", "Europe", "CZE", "Europe", "DNK", "Europe", "EST", "Europe",
  "FIN", "Europe", "FRA", "Europe", "DEU", "Europe", "GRC", "Europe",
  "HUN", "Europe", "ISL", "Europe", "IRL", "Europe", "ITA", "Europe",
  "LVA", "Europe", "LIE", "Europe", "LTU", "Europe", "LUX", "Europe",
  "MLT", "Europe", "MDA", "Europe", "MCO", "Europe", "MNE", "Europe",
  "NLD", "Europe", "MKD", "Europe", "NOR", "Europe", "POL", "Europe",
  "PRT", "Europe", "ROU", "Europe", "RUS", "Europe", "SMR", "Europe",
  "SRB", "Europe", "SVK", "Europe", "SVN", "Europe", "ESP", "Europe",
  "SWE", "Europe", "CHE", "Europe", "TUR", "Europe", "UKR", "Europe",
  "GBR", "Europe", "VAT", "Europe",
  # Oceania
  "AUS", "Oceania", "FJI", "Oceania", "KIR", "Oceania", "MHL", "Oceania",
  "FSM", "Oceania", "NRU", "Oceania", "NZL", "Oceania", "PLW", "Oceania",
  "PNG", "Oceania", "WSM", "Oceania", "SLB", "Oceania", "TON", "Oceania",
  "TUV", "Oceania", "VUT", "Oceania"
)

### |- filter to exports + world partner ----
wto_clean <- wto_raw |>
  filter(
    indicator == "Merchandise exports by product group - annual",
    partner == "World"
  ) |>
  rename(
    country     = reporter,
    iso3        = reporter_iso3a,
    value_usd_m = value
  ) |>
  filter(!is.na(value_usd_m), value_usd_m > 0)

### |- keep three top-level product groups only ----
product_groups <- c(
  "Agricultural products",
  "Fuels and mining products",
  "Manufactures"
)

wto_filtered <- wto_clean |>
  filter(product %in% product_groups)

### |- attach OWID regions ----
wto_regions <- wto_filtered |>
  left_join(owid_regions, by = "iso3") |>
  filter(!is.na(region))

### |- 5-year average (2019–2023) ----
wto_avg <- wto_regions |>
  filter(year %in% 2019:2023) |>
  group_by(region, product) |>
  summarise(
    avg_value = mean(value_usd_m, na.rm = TRUE),
    .groups   = "drop"
  )

# housekeeping
rm(wto_raw, wto_clean, wto_filtered, wto_regions)
gc()

### |- recode product labels for display ----
wto_avg <- wto_avg |>
  mutate(
    product_label = case_when(
      product == "Agricultural products" ~ "Agriculture",
      product == "Fuels and mining products" ~ "Fuels & Mining",
      product == "Manufactures" ~ "Manufactures",
      TRUE ~ product
    )
  )

### |- order regions ----
region_order <- c("Asia", "Europe", "Americas", "Africa", "Oceania") 

product_order <- c("Agriculture", "Fuels & Mining", "Manufactures")

wto_avg <- wto_avg |>
  mutate(
    region        = factor(region, levels = region_order),
    product_label = factor(product_label, levels = product_order)
  )

### |- build alluvial-ready data ----
alluvial_data <- wto_avg |>
  filter(!is.na(region), !is.na(product_label)) |>
  rename(
    origin_region = region,
    product_group = product_label,
    flow_value    = avg_value
  )
```
          used (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 1442718 77.1    2460380 131.4  2460380 131.4
Vcells 2520011 19.3   31855280 243.1 39818964 303.8

5. Visualization Parameters

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

### |- plot aesthetics ----
colors <- get_theme_colors(
  palette = c(
    "Agriculture"    = "#7FB069",   
    "Fuels & Mining" = "#D08C60",   
    "Manufactures"   = "#7A1E2C" 
  )
)

### |- titles and caption ----
title_text <- "Global Trade Connects Regions Through a Few Dominant Product Flows"

subtitle_text <- glue(
  "Average annual exports by **region** and **product group** (2019–2023)"
)

caption_text <- create_dcc_caption(
  dcc_year    = 2026,
  dcc_day     = 14,
  source_text = "WTO Statistics Portal — Merchandise Trade Values by Product Group"
)

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

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

weekly_theme <- extend_weekly_theme(
  base_theme,
  theme(
    # Axes
    axis.text.x   = element_blank(),
    axis.text.y   = element_text(size = 9, family = fonts$text),
    axis.ticks    = element_blank(),
    axis.title    = element_blank(),
    
    # Grid
    panel.grid    = element_blank(),
    
    # Legend
    legend.position = "top",
    legend.title    = element_text(size = 9, family = fonts$text, face = "bold"),
    legend.text     = element_text(size = 9, family = fonts$text),
    
    # Titles
    plot.title = element_text(
      size = 16, face = "bold", family = fonts$title,
      margin = margin(b = 6)
    ),
    plot.subtitle = element_markdown(
      size = 10, family = fonts$text, color = "gray40",
      margin = margin(b = 16)
    ),
    plot.caption = element_markdown(
      size = 7, family = fonts$text, color = "gray55",
      hjust = 0, margin = margin(t = 12)
    ),
    plot.margin = margin(20, 20, 12, 20)
  )
)

theme_set(weekly_theme)
```

6. Plot

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

### |- main plot ----
p <- ggplot(
  alluvial_data,
  aes(
    axis1 = origin_region,
    axis2 = product_group,
    y  = flow_value,
    fill = product_group
   )
  ) +
  # Geoms
  geom_alluvium(
    aes(fill = product_group),
    alpha = 0.70,
    width = 1 / 4,
    knot.pos = 0.4
  ) +
  geom_stratum(
    width = 1 / 4,
    fill = "gray92",
    color = "white",
    linewidth = 0.4
  ) +
  geom_text(
    stat = "stratum",
    aes(label = ifelse(after_stat(x) == 1, as.character(after_stat(stratum)), "")),
    size = 3,
    fontface = "bold",
    family = fonts$text,
    color = "gray20"
  ) +
  # Scales
  scale_fill_manual(
    values = colors$palette,
    name = "Product Group",
    breaks = product_order
  ) +
  scale_y_continuous(
    labels = label_comma(scale = 1e-3, suffix = "B"),
    expand = expansion(mult = c(0.02, 0.02))
  ) +
  scale_x_continuous(
    expand = expansion(add = c(0.5, 0.8))
  ) +
  # Labs
  labs(
    title = title_text,
    subtitle = subtitle_text,
    caption = caption_text,
    y = "Average Annual Exports (USD billions)"
  )

### |- right-side text labels + insight annotation ----
p_final <- p +
  geom_text(
    stat = "stratum",
    aes(label = ifelse(after_stat(x) == 2, as.character(after_stat(stratum)), "")),
    size = 2.8,
    fontface = "plain",
    family = fonts$text,
    color = "gray40",
    hjust = -0.15
  ) +
  annotate(
    "text",
    x = 2.18, y = max(alluvial_data$flow_value) * 0.08,
    label = "Manufactured goods dominate\nexports across all regions",
    fontface = "italic",
    size = 2.8, family = fonts$text, color = "gray40",
    hjust = 0, lineheight = 1.3
  )
```

7. Save

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

### |-  plot image ----  
save_plot(
  p_final, 
  type = "30daychartchallenge", 
  year = 2026, 
  day = 14, 
  width = 8, 
  height = 10
  )
```

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        ggalluvial_0.12.6 glue_1.8.0        scales_1.4.0     
 [5] janitor_2.2.1     showtext_0.9-7    showtextdb_3.0    sysfonts_0.8.9   
 [9] ggtext_0.1.2      lubridate_1.9.5   forcats_1.0.1     stringr_1.6.0    
[13] dplyr_1.2.0       purrr_1.2.1       readr_2.2.0       tidyr_1.3.2      
[17] tibble_3.2.1      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] parallel_4.3.1     gifski_1.32.0-2    pacman_0.5.1       pkgconfig_2.0.3   
[13] RColorBrewer_1.1-3 S7_0.2.0           lifecycle_1.0.5    compiler_4.3.1    
[17] farver_2.1.2       textshaping_1.0.4  codetools_0.2-19   snakecase_0.11.1  
[21] litedown_0.9       htmltools_0.5.9    yaml_2.3.12        pillar_1.11.1     
[25] crayon_1.5.3       camcorder_0.1.0    magick_2.8.6       commonmark_2.0.0  
[29] tidyselect_1.2.1   digest_0.6.39      stringi_1.8.7      labeling_0.4.3    
[33] rsvg_2.6.2         rprojroot_2.1.1    fastmap_1.2.0      grid_4.3.1        
[37] cli_3.6.5          magrittr_2.0.3     withr_3.0.2        bit64_4.6.0-1     
[41] timechange_0.4.0   rmarkdown_2.30     bit_4.6.0          otel_0.2.0        
[45] ragg_1.5.0         hms_1.1.4          evaluate_1.0.5     knitr_1.51        
[49] markdown_2.0       rlang_1.1.7        gridtext_0.1.6     Rcpp_1.1.1        
[53] xml2_1.5.2         svglite_2.1.3      rstudioapi_0.18.0  vroom_1.7.0       
[57] jsonlite_2.0.0     R6_2.6.1           systemfonts_1.3.2 

9. GitHub Repository

TipExpand for GitHub Repo

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

For the full repository, click here.

10. References

TipExpand for References
  1. Data Sources:
    • WTO Statistics Portal. (2024). Merchandise trade values annual dataset. World Trade Organization. https://data.wto.org/en/dataset/bulkdownload
  2. Article:
    • Ortiz-Ospina, E., & Roser, M. (2018). Trade and globalization. Our World in Data. https://ourworldindata.org/trade-and-globalization

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 = {Global {Trade} {Connects} {Regions} {Through} a {Few}
    {Dominant} {Product} {Flows}},
  date = {2026-04-14},
  url = {https://stevenponce.netlify.app/data_visualizations/30DayChartChallenge/2026/30dcc_2026_14.html},
  langid = {en}
}
For attribution, please cite this work as:
Ponce, Steven. 2026. “Global Trade Connects Regions Through a Few Dominant Product Flows.” April 14, 2026. https://stevenponce.netlify.app/data_visualizations/30DayChartChallenge/2026/30dcc_2026_14.html.
Source Code
---
title: "Global Trade Connects Regions Through a Few Dominant Product Flows"
subtitle: "Average annual exports by region and product group (2019–2023)"
description: "An alluvial chart mapping average merchandise exports (2019–2023) from five world regions to three product groups — Agriculture, Fuels & Mining, and Manufactures. Built with ggalluvial in R, the chart reveals that manufactured goods dominate export flows across every region, with Asia and Europe leading in volume. Day 14 of the #30DayChartChallenge 2026."
date: "2026-04-14" 
author:
  - name: "Steven Ponce"
    url: "https://stevenponce.netlify.app"
citation:
  url: "https://stevenponce.netlify.app/data_visualizations/30DayChartChallenge/2026/30dcc_2026_14.html"
categories: ["30DayChartChallenge", "Data Visualization", "R Programming", "2026"]
tags: [
  "30DayChartChallenge",
  "Relationships",
  "Trade",
  "Alluvial Chart",
  "Sankey",
  "ggalluvial",
  "Global Trade",
  "Merchandise Exports",
  "WTO",
  "Regional Analysis",
  "ggplot2"
]
image: "thumbnails/30dcc_2026_14.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
---

![An alluvial (Sankey-style) chart titled "Global Trade Connects Regions Through a Few Dominant Product Flows." The left axis shows five world regions — Asia, Europe, the Americas, Africa, and Oceania — ordered from the largest to the smallest exporter. Flows connect each region to one of three product groups on the right: Agriculture (green), Fuels & Mining (copper), and Manufacturing (burgundy). Asia and Europe generate the widest flows, with manufactured goods — shown in deep burgundy — dominating exports across every region. Fuels & Mining flows are most prominent from the Americas and Africa. Agriculture flows are thin across all regions. Data represent average annual merchandise exports from 2019 to 2023, sourced from the WTO Statistics Portal.](30dcc_2026_14.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, ggalluvial
  )
})

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

wto_raw <- read_csv(
  here::here("data/30DayChartChallenge/2026/wto_merchandise_values_annual_dataset.csv"),
  locale = locale(encoding = "latin1")
  ) |>
  clean_names() 
```

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

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

glimpse(wto_raw)
```

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

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

### |- OWID continent lookup ----
owid_regions <- tribble(
  ~iso3,  ~region,
  # Africa
  "DZA", "Africa", "AGO", "Africa", "BEN", "Africa", "BWA", "Africa",
  "BFA", "Africa", "BDI", "Africa", "CPV", "Africa", "CMR", "Africa",
  "CAF", "Africa", "TCD", "Africa", "COM", "Africa", "COD", "Africa",
  "COG", "Africa", "CIV", "Africa", "DJI", "Africa", "EGY", "Africa",
  "GNQ", "Africa", "ERI", "Africa", "SWZ", "Africa", "ETH", "Africa",
  "GAB", "Africa", "GMB", "Africa", "GHA", "Africa", "GIN", "Africa",
  "GNB", "Africa", "KEN", "Africa", "LSO", "Africa", "LBR", "Africa",
  "LBY", "Africa", "MDG", "Africa", "MWI", "Africa", "MLI", "Africa",
  "MRT", "Africa", "MUS", "Africa", "MAR", "Africa", "MOZ", "Africa",
  "NAM", "Africa", "NER", "Africa", "NGA", "Africa", "RWA", "Africa",
  "STP", "Africa", "SEN", "Africa", "SLE", "Africa", "SOM", "Africa",
  "ZAF", "Africa", "SSD", "Africa", "SDN", "Africa", "TZA", "Africa",
  "TGO", "Africa", "TUN", "Africa", "UGA", "Africa", "ZMB", "Africa",
  "ZWE", "Africa",
  # Americas
  "ARG", "Americas", "BHS", "Americas", "BRB", "Americas", "BLZ", "Americas",
  "BOL", "Americas", "BRA", "Americas", "CAN", "Americas", "CHL", "Americas",
  "COL", "Americas", "CRI", "Americas", "CUB", "Americas", "DOM", "Americas",
  "ECU", "Americas", "SLV", "Americas", "GTM", "Americas", "GUY", "Americas",
  "HTI", "Americas", "HND", "Americas", "JAM", "Americas", "MEX", "Americas",
  "NIC", "Americas", "PAN", "Americas", "PRY", "Americas", "PER", "Americas",
  "TTO", "Americas", "USA", "Americas", "URY", "Americas", "VEN", "Americas",
  # Asia
  "AFG", "Asia", "ARM", "Asia", "AZE", "Asia", "BGD", "Asia",
  "BTN", "Asia", "BRN", "Asia", "KHM", "Asia", "CHN", "Asia",
  "GEO", "Asia", "IND", "Asia", "IDN", "Asia", "IRN", "Asia",
  "IRQ", "Asia", "ISR", "Asia", "JPN", "Asia", "JOR", "Asia",
  "KAZ", "Asia", "PRK", "Asia", "KOR", "Asia", "KWT", "Asia",
  "KGZ", "Asia", "LAO", "Asia", "LBN", "Asia", "MYS", "Asia",
  "MDV", "Asia", "MNG", "Asia", "MMR", "Asia", "NPL", "Asia",
  "OMN", "Asia", "PAK", "Asia", "PSE", "Asia", "PHL", "Asia",
  "QAT", "Asia", "SAU", "Asia", "SGP", "Asia", "LKA", "Asia",
  "SYR", "Asia", "TWN", "Asia", "TJK", "Asia", "THA", "Asia",
  "TLS", "Asia", "TKM", "Asia", "ARE", "Asia", "UZB", "Asia",
  "VNM", "Asia", "YEM", "Asia",
  # Europe
  "ALB", "Europe", "AND", "Europe", "AUT", "Europe", "BLR", "Europe",
  "BEL", "Europe", "BIH", "Europe", "BGR", "Europe", "HRV", "Europe",
  "CYP", "Europe", "CZE", "Europe", "DNK", "Europe", "EST", "Europe",
  "FIN", "Europe", "FRA", "Europe", "DEU", "Europe", "GRC", "Europe",
  "HUN", "Europe", "ISL", "Europe", "IRL", "Europe", "ITA", "Europe",
  "LVA", "Europe", "LIE", "Europe", "LTU", "Europe", "LUX", "Europe",
  "MLT", "Europe", "MDA", "Europe", "MCO", "Europe", "MNE", "Europe",
  "NLD", "Europe", "MKD", "Europe", "NOR", "Europe", "POL", "Europe",
  "PRT", "Europe", "ROU", "Europe", "RUS", "Europe", "SMR", "Europe",
  "SRB", "Europe", "SVK", "Europe", "SVN", "Europe", "ESP", "Europe",
  "SWE", "Europe", "CHE", "Europe", "TUR", "Europe", "UKR", "Europe",
  "GBR", "Europe", "VAT", "Europe",
  # Oceania
  "AUS", "Oceania", "FJI", "Oceania", "KIR", "Oceania", "MHL", "Oceania",
  "FSM", "Oceania", "NRU", "Oceania", "NZL", "Oceania", "PLW", "Oceania",
  "PNG", "Oceania", "WSM", "Oceania", "SLB", "Oceania", "TON", "Oceania",
  "TUV", "Oceania", "VUT", "Oceania"
)

### |- filter to exports + world partner ----
wto_clean <- wto_raw |>
  filter(
    indicator == "Merchandise exports by product group - annual",
    partner == "World"
  ) |>
  rename(
    country     = reporter,
    iso3        = reporter_iso3a,
    value_usd_m = value
  ) |>
  filter(!is.na(value_usd_m), value_usd_m > 0)

### |- keep three top-level product groups only ----
product_groups <- c(
  "Agricultural products",
  "Fuels and mining products",
  "Manufactures"
)

wto_filtered <- wto_clean |>
  filter(product %in% product_groups)

### |- attach OWID regions ----
wto_regions <- wto_filtered |>
  left_join(owid_regions, by = "iso3") |>
  filter(!is.na(region))

### |- 5-year average (2019–2023) ----
wto_avg <- wto_regions |>
  filter(year %in% 2019:2023) |>
  group_by(region, product) |>
  summarise(
    avg_value = mean(value_usd_m, na.rm = TRUE),
    .groups   = "drop"
  )

# housekeeping
rm(wto_raw, wto_clean, wto_filtered, wto_regions)
gc()

### |- recode product labels for display ----
wto_avg <- wto_avg |>
  mutate(
    product_label = case_when(
      product == "Agricultural products" ~ "Agriculture",
      product == "Fuels and mining products" ~ "Fuels & Mining",
      product == "Manufactures" ~ "Manufactures",
      TRUE ~ product
    )
  )

### |- order regions ----
region_order <- c("Asia", "Europe", "Americas", "Africa", "Oceania") 

product_order <- c("Agriculture", "Fuels & Mining", "Manufactures")

wto_avg <- wto_avg |>
  mutate(
    region        = factor(region, levels = region_order),
    product_label = factor(product_label, levels = product_order)
  )

### |- build alluvial-ready data ----
alluvial_data <- wto_avg |>
  filter(!is.na(region), !is.na(product_label)) |>
  rename(
    origin_region = region,
    product_group = product_label,
    flow_value    = avg_value
  )
```


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

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

### |- plot aesthetics ----
colors <- get_theme_colors(
  palette = c(
    "Agriculture"    = "#7FB069",   
    "Fuels & Mining" = "#D08C60",   
    "Manufactures"   = "#7A1E2C" 
  )
)

### |- titles and caption ----
title_text <- "Global Trade Connects Regions Through a Few Dominant Product Flows"

subtitle_text <- glue(
  "Average annual exports by **region** and **product group** (2019–2023)"
)

caption_text <- create_dcc_caption(
  dcc_year    = 2026,
  dcc_day     = 14,
  source_text = "WTO Statistics Portal — Merchandise Trade Values by Product Group"
)

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

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

weekly_theme <- extend_weekly_theme(
  base_theme,
  theme(
    # Axes
    axis.text.x   = element_blank(),
    axis.text.y   = element_text(size = 9, family = fonts$text),
    axis.ticks    = element_blank(),
    axis.title    = element_blank(),
    
    # Grid
    panel.grid    = element_blank(),
    
    # Legend
    legend.position = "top",
    legend.title    = element_text(size = 9, family = fonts$text, face = "bold"),
    legend.text     = element_text(size = 9, family = fonts$text),
    
    # Titles
    plot.title = element_text(
      size = 16, face = "bold", family = fonts$title,
      margin = margin(b = 6)
    ),
    plot.subtitle = element_markdown(
      size = 10, family = fonts$text, color = "gray40",
      margin = margin(b = 16)
    ),
    plot.caption = element_markdown(
      size = 7, family = fonts$text, color = "gray55",
      hjust = 0, margin = margin(t = 12)
    ),
    plot.margin = margin(20, 20, 12, 20)
  )
)

theme_set(weekly_theme)

```

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

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

### |- main plot ----
p <- ggplot(
  alluvial_data,
  aes(
    axis1 = origin_region,
    axis2 = product_group,
    y  = flow_value,
    fill = product_group
   )
  ) +
  # Geoms
  geom_alluvium(
    aes(fill = product_group),
    alpha = 0.70,
    width = 1 / 4,
    knot.pos = 0.4
  ) +
  geom_stratum(
    width = 1 / 4,
    fill = "gray92",
    color = "white",
    linewidth = 0.4
  ) +
  geom_text(
    stat = "stratum",
    aes(label = ifelse(after_stat(x) == 1, as.character(after_stat(stratum)), "")),
    size = 3,
    fontface = "bold",
    family = fonts$text,
    color = "gray20"
  ) +
  # Scales
  scale_fill_manual(
    values = colors$palette,
    name = "Product Group",
    breaks = product_order
  ) +
  scale_y_continuous(
    labels = label_comma(scale = 1e-3, suffix = "B"),
    expand = expansion(mult = c(0.02, 0.02))
  ) +
  scale_x_continuous(
    expand = expansion(add = c(0.5, 0.8))
  ) +
  # Labs
  labs(
    title = title_text,
    subtitle = subtitle_text,
    caption = caption_text,
    y = "Average Annual Exports (USD billions)"
  )

### |- right-side text labels + insight annotation ----
p_final <- p +
  geom_text(
    stat = "stratum",
    aes(label = ifelse(after_stat(x) == 2, as.character(after_stat(stratum)), "")),
    size = 2.8,
    fontface = "plain",
    family = fonts$text,
    color = "gray40",
    hjust = -0.15
  ) +
  annotate(
    "text",
    x = 2.18, y = max(alluvial_data$flow_value) * 0.08,
    label = "Manufactured goods dominate\nexports across all regions",
    fontface = "italic",
    size = 2.8, family = fonts$text, color = "gray40",
    hjust = 0, lineheight = 1.3
  )
```

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

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

### |-  plot image ----  
save_plot(
  p_final, 
  type = "30daychartchallenge", 
  year = 2026, 
  day = 14, 
  width = 8, 
  height = 10
  )
```

#### [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_14.qmd`](https://github.com/poncest/personal-website/blob/master/data_visualizations/TidyTuesday/2026/30dcc_2026_14.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:
   - WTO Statistics Portal. (2024). *Merchandise trade values annual dataset*. World Trade Organization. https://data.wto.org/en/dataset/bulkdownload

2. Article:
   - Ortiz-Ospina, E., & Roser, M. (2018). *Trade and globalization*. Our World in Data. https://ourworldindata.org/trade-and-globalization
:::


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