---
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", "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"
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
---
{#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)
:::