• 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

Italy industrialized unevenly

  • Show All Code
  • Hide All Code

  • View Source

Indexed production reveals diverging paths across Italian industries, 1861–1985

TidyTuesday
Data Visualization
R Programming
2026
A two-panel chart examining over a century of Italian industrial production using ISTAT historical data. Panel A indexes Raw Silk and Total Textiles to their first available year (= 100), revealing diverging trajectories: silk peaked around 1910 and entered long structural decline, while textiles recovered strongly after WWII and stabilized as a postwar manufacturing anchor. Panel B tracks average gross tonnage per ship launched — a derived metric showing Italy’s shipbuilding shift from many small vessels to fewer, heavier ones, peaking at 14,692 tons/ship in the early 1970s. Built with ggplot2 and patchwork in R.
Author

Steven Ponce

Published

May 3, 2026

Figure 1: A two-panel chart titled “Italy industrialized unevenly.” Panel A shows indexed production (first year = 100) for Raw Silk and Total Textiles from 1863 to 1985. Raw Silk (steel blue) rises to nearly 3× its baseline by 1910, then enters a long structural decline, falling below its starting value after World War II and continuing downward through 1985. Total Textiles (rust orange) begins observation around 1930, dips sharply during the WWII collapse annotated near 1944, then recovers strongly in the postwar period, stabilizing around 2–2.5× its baseline by the 1970s–80s. A dotted vertical line marks 1951, when Italy shifted from fiscal-year to calendar-year reporting. Panel B shows average gross tonnage per ship launched from 1861 to 1985. Ships remained small through the early industrial period, surged briefly around WWI, then plateaued at low levels through the mid-century. A sharp rise peaks at 14,692 tons per ship in the early 1970s — marking Italy’s shift from launching many small vessels to fewer, heavier ones — before declining steeply through the 1980s.

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({
if (!require("pacman")) install.packages("pacman")
pacman::p_load(
    tidyverse, ggtext, showtext, janitor, ggrepel,      
    scales, glue, skimr, patchwork
    )
})

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

tt <- tidytuesdayR::tt_load(2026, week = 18)

food_beverages <- tt$food_beverages |> clean_names()
textiles <- tt$textiles |> clean_names()
transport <- tt$transport |> clean_names()

rm(tt)
```

3. Examine the Data

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

glimpse(food_beverages)
glimpse(textiles)
glimpse(transport)
```

4. Tidy Data

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

### |- Panel A: Indexed growth series ----
# Select 5 representative series across the three datasets.
# Index each to its own first non-NA year (= 100) so cross-industry
# comparisons reflect relative change, not raw volume or units.
panel_a_raw <- bind_rows(
  food_beverages |>
    select(year, beer, sugar, ethyl_alcohol_1) |>
    pivot_longer(-year, names_to = "series", values_to = "value"),
  textiles |>
    select(year, total_textiles, raw_silk) |>
    pivot_longer(-year, names_to = "series", values_to = "value")
)

panel_a_indexed <- panel_a_raw |>
  filter(!is.na(value)) |>
  filter(series %in% c("total_textiles", "raw_silk")) |>
  group_by(series) |>
  mutate(
    base_value = first(value),
    base_year  = first(year),
    indexed    = value / base_value * 100
  ) |>
  ungroup() |>
  mutate(
    series_label = case_when(
      series == "total_textiles" ~ "Total Textiles",
      series == "raw_silk" ~ "Raw Silk"
    ),
    color_role = case_when(
      series == "raw_silk" ~ "decline",
      series == "total_textiles" ~ "core"
    )
  )

### |- Panel B: Average ship weight (derived metric) ----
# avg_ship_weight = ships_weight / ships_launched
# A proxy for industrial capability: fewer but heavier ships = upgrading

panel_b <- transport |>
  filter(!is.na(ships_weight), !is.na(ships_launched), ships_launched > 0) |>
  mutate(avg_ship_weight = ships_weight / ships_launched) |>
  select(year, avg_ship_weight, ships_launched, ships_weight)

# Identify annotatable inflection points for Panel B narrative
panel_b_annotations <- panel_b |>
  summarise(
    early_median  = median(avg_ship_weight[year <= 1900], na.rm = TRUE),
    late_median = median(avg_ship_weight[year >= 1960], na.rm = TRUE),
    peak_year = year[which.max(avg_ship_weight)],
    peak_val = max(avg_ship_weight, na.rm = TRUE)
  )
```

5. Visualization Parameters

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

### |- plot aesthetics ----
colors <- get_theme_colors(
    palette = list(
        "rise"    = "#722F37", 
        "decline" = "#4A6FA5", 
        "core"    = "#C26A3D", 
        "neutral" = "gray75"   
    )
)

### |- titles and captions ----
title_text    <- str_glue("Italy industrialized unevenly")

subtitle_a    <- str_glue(
    "Indexed to first available year (= 100).",
    " Silk declined; textiles rose and stabilized.<br>",
    "<span style='color:{colors$palette$decline}'>Raw Silk</span>: Italy's oldest fiber industry, in long retreat;",
    " <span style='color:{colors$palette$core}'>Total Textiles</span>: postwar manufacturing anchor."
)

title_b <- str_glue("Ships became fewer but heavier")
subtitle_b <- str_glue(
    "Average gross tonnage per ship launched — a proxy for industrial capability."
)

caption_text  <- create_social_caption(
    tt_year = 2026,
    tt_week = 18,
    source_text = "ISTAT — Sommari di statistiche storiche (1861–1985)"
)

caption_b_note <- str_glue(
    "Note: Before 1951, values refer to fiscal years; from 1951 onward, calendar years."
)

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

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

weekly_theme <- extend_weekly_theme(
  base_theme,
  theme(
    plot.title = element_text(
      face = "bold", family = fonts$title,
      size = rel(1.3), hjust = 0, margin = margin(b = 4)
    ),
    plot.subtitle = element_markdown(
      family = fonts$text,
      size = rel(0.85), hjust = 0,
      lineheight = 1.3, margin = margin(b = 10)
    ),
    plot.caption = element_markdown(
      family = fonts$text,
      size   = rel(0.7), hjust = 0,
      color  = "gray50", margin = margin(t = 10)
    ),
    axis.title = element_text(
      family = fonts$text, size = rel(0.8), color = "gray40"
    ),
    axis.text = element_text(
      family = fonts$text, size = rel(0.75), color = "gray50"
    ),
    panel.grid.major.y = element_line(color = "gray92", linewidth = 0.3),
    panel.grid.major.x = element_blank(),
    panel.grid.minor = element_blank(),
    axis.ticks = element_blank(),
    strip.text = element_blank()
  )
)

theme_set(weekly_theme)
```

6. Plot

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

### |- Panel A: Indexed divergence ----

role_colors <- c(
  "decline" = colors$palette$decline,
  "core"    = colors$palette$core
)

role_linewidth <- c(
  "decline" = 1.4,
  "core"    = 1.4
)

role_alpha <- c(
  "decline" = 1,
  "core"    = 1
)

p_a <- panel_a_indexed |>
  ggplot(aes(
    x = year, y = indexed,
    group = series_label,
    color = color_role,
    linewidth = color_role,
    alpha = color_role
  )) +
  annotate("rect",
    xmin = 1915, xmax = 1918,
    ymin = -Inf, ymax = Inf,
    fill = "gray80", alpha = 0.10
  ) +
  annotate("rect",
    xmin = 1940, xmax = 1945,
    ymin = -Inf, ymax = Inf,
    fill = "gray80", alpha = 0.10
  ) +
  geom_vline(
    xintercept = 1951,
    linetype   = "dotted",
    linewidth  = 0.3,
    color      = "gray65"
  ) +
  annotate(
    "text",
    x = 1952, y = Inf,
    label = "Calendar-year reporting begins",
    hjust = 0, vjust = 1.5,
    size = 2.5,
    family = fonts$text,
    color = "gray45"
  ) +
  # Geoms
  geom_hline(
    yintercept = 100, linetype = "dashed",
    linewidth = 0.3, color = "gray60"
  ) +
  geom_line(lineend = "round") +
  geom_text(
    data = panel_a_indexed |>
      group_by(series_label, color_role) |>
      slice_max(year, n = 1) |>
      ungroup() |>
      mutate(
        y_nudge = case_when(
          series_label == "Raw Silk" ~ -12,
          series_label == "Total Textiles" ~ 8,
          TRUE ~ 0
        ),
        y_final = indexed + y_nudge
      ),
    aes(x = year, y = y_final, label = series_label, color = color_role),
    hjust = -0.12, size = 2.8,
    family = fonts$text,
    fontface = "bold",
    show.legend = FALSE
  ) +
  # Scales
  scale_color_manual(values = role_colors, guide = "none") +
  scale_linewidth_manual(values = role_linewidth, guide = "none") +
  scale_alpha_manual(values = role_alpha, guide = "none") +
  scale_x_continuous(
    breaks = seq(1870, 1980, by = 20),
    expand = expansion(mult = c(0.02, 0.18))
  ) +
  scale_y_continuous(
    labels = label_number(suffix = "×", scale = 0.01, accuracy = 0.1),
    breaks = c(0, 0.5, 1, 1.5, 2, 2.5, 3) * 100,
    limits = c(0, NA)
  ) +
  coord_cartesian(clip = "off") +
  # annotate
  annotate("text",
    x = 1916.5, y = Inf,
    label = "WWI", hjust = 0.5, vjust = 2,
    size = 2.3, color = "gray50", family = fonts$text
  ) +
  annotate("text",
    x = 1942.5, y = Inf,
    label = "WWII", hjust = 0.5, vjust = 2,
    size = 2.3, color = "gray50", family = fonts$text
  ) +
  annotate("text",
    x = 1944, y = 0.35,
    label = "WWII collapse",
    hjust = 0.5, vjust = 1,
    size = 2.4, color = "gray45",
    family = fonts$text
  ) +
  # Labs
  labs(
    subtitle = subtitle_a,
    x = NULL,
    y = "Production index"
  )

### |- Panel B: Ship sophistication ----

# Find key annotation years
peak_row <- panel_b |> slice_max(avg_ship_weight, n = 1)
early_row <- panel_b |>
  filter(year <= 1890) |>
  slice_min(year, n = 1)

p_b <- panel_b |>
  ggplot(aes(x = year, y = avg_ship_weight)) +
  # Geoms
  geom_line(
    color     = colors$palette$core,
    linewidth = 0.85,
    lineend   = "round"
  ) +
  # Annotate
  annotate("text",
    x = 1878, y = 1800,
    label = "Many small ships\n(capacity era)",
    hjust = 0.5, vjust = 0,
    size = 2.6, color = "gray45",
    family = fonts$text, lineheight = 1.2
  ) +
  annotate("point",
    x = peak_row$year, y = peak_row$avg_ship_weight,
    color = colors$palette$rise, size = 2.2
  ) +
  annotate("text",
    x = peak_row$year + 2, y = peak_row$avg_ship_weight + 2200,
    label = glue("{scales::comma(round(peak_row$avg_ship_weight))} tons/ship"),
    hjust = 0, vjust = 0,
    size = 2.4, color = "gray35",
    family = fonts$text, lineheight = 1.2
  ) +
  annotate("text",
    x = 1965, y = peak_row$avg_ship_weight * 0.55,
    label = "Fewer, heavier ships\n(capability era)",
    hjust = 0.5, vjust = 1,
    size = 2.6, color = "gray45",
    family = fonts$text, lineheight = 1.2
  ) +

  # Scales
  scale_x_continuous(breaks = seq(1860, 1980, by = 20)) +
  scale_y_continuous(labels = label_comma()) +
  # Scales
  labs(
    title = title_b,
    subtitle = subtitle_b,
    x = NULL,
    y = "Avg. gross tonnage per ship (tons)",
    caption = glue("{caption_b_note}<br>{caption_text}")
  ) +
  # Theme
  theme(
    plot.title = element_text(
      face   = "bold",
      family = fonts$title,
      size   = rel(1.05),
      hjust  = 0,
      margin = margin(b = 3)
    ),
    plot.subtitle = element_markdown(
      family   = 'sans',
      size     = rel(0.8),
      hjust    = 0,
      color    = "gray40",
      margin   = margin(b = 8)
    )
  )

### |- Combine plots ----

p_final <- (p_a / p_b) +
  plot_layout(heights = c(1.55, 1)) +
  plot_annotation(
    title = title_text,
    theme = theme(
      plot.title = element_text(
        face   = "bold",
        family = fonts$title,
        size   = rel(1.6),
        hjust  = 0,
        margin = margin(b = 6)
      ),
      plot.margin = margin(t = 16, r = 20, b = 12, l = 16)
    )
  )
```

7. Save

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

### |-  plot image ----  
save_plot_patchwork(
  plot = p_final, 
  type = "tidytuesday", 
  year = 2026, 
  week = 18, 
  width  = 11,
  height = 10
  )
```

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] here_1.0.2      patchwork_1.3.2 skimr_2.2.2     glue_1.8.0     
 [5] scales_1.4.0    ggrepel_0.9.8   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.3  
[21] tidyverse_2.0.0 pacman_0.5.1   

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

9. GitHub Repository

TipExpand for GitHub Repo

The complete code for this analysis is available in tt_2026_18.qmd.

For the full repository, click here.

10. References

TipExpand for References
  1. Data Source:
    • TidyTuesday 2026 Week 18: Italian Industrial Production

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 = {Italy Industrialized Unevenly},
  date = {2026-05-03},
  url = {https://stevenponce.netlify.app/data_visualizations/TidyTuesday/2026/tt_2026_18.html},
  langid = {en}
}
For attribution, please cite this work as:
Ponce, Steven. 2026. “Italy Industrialized Unevenly.” May 3. https://stevenponce.netlify.app/data_visualizations/TidyTuesday/2026/tt_2026_18.html.
Source Code
---
title: "Italy industrialized unevenly"
subtitle: "Indexed production reveals diverging paths across Italian industries, 1861–1985"
description: "A two-panel chart examining over a century of Italian industrial production using ISTAT historical data. Panel A indexes Raw Silk and Total Textiles to their first available year (= 100), revealing diverging trajectories: silk peaked around 1910 and entered long structural decline, while textiles recovered strongly after WWII and stabilized as a postwar manufacturing anchor. Panel B tracks average gross tonnage per ship launched — a derived metric showing Italy's shipbuilding shift from many small vessels to fewer, heavier ones, peaking at 14,692 tons/ship in 
the early 1970s. Built with ggplot2 and patchwork in R."
date: "2026-05-03"
author:
  - name: "Steven Ponce"
    url: "https://stevenponce.netlify.app"
citation:
  url: "https://stevenponce.netlify.app/data_visualizations/TidyTuesday/2026/tt_2026_18.html" 
categories: ["TidyTuesday", "Data Visualization", "R Programming", "2026"]
tags: [
  "Agricultural Tariffs",
]
image: "thumbnails/tt_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 two-panel chart titled "Italy industrialized unevenly." Panel A shows indexed production (first year = 100) for Raw Silk and Total Textiles from 1863 to 1985. Raw Silk (steel blue) rises to nearly 3× its baseline by 1910, then enters a long structural decline, falling below its starting value after World War II and continuing downward through 1985. Total Textiles (rust orange) begins observation around 1930, dips sharply during the WWII collapse annotated near 1944, then recovers strongly in the postwar period, stabilizing around 2–2.5× its baseline by the 1970s–80s. A dotted vertical line marks 1951, when Italy shifted from fiscal-year to calendar-year reporting. Panel B shows average gross tonnage per ship launched from 1861 to 1985. Ships remained small through the early industrial period, surged briefly around WWI, then plateaued at low levels through the mid-century. A sharp rise peaks at 14,692 tons per ship in the early 1970s — marking Italy's shift from launching many small vessels to fewer, heavier ones — before declining steeply through the 1980s.](tt_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({
if (!require("pacman")) install.packages("pacman")
pacman::p_load(
    tidyverse, ggtext, showtext, janitor, ggrepel,      
    scales, glue, skimr, patchwork
    )
})

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

tt <- tidytuesdayR::tt_load(2026, week = 18)

food_beverages <- tt$food_beverages |> clean_names()
textiles <- tt$textiles |> clean_names()
transport <- tt$transport |> clean_names()

rm(tt)
```

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

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

glimpse(food_beverages)
glimpse(textiles)
glimpse(transport)
```

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

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

### |- Panel A: Indexed growth series ----
# Select 5 representative series across the three datasets.
# Index each to its own first non-NA year (= 100) so cross-industry
# comparisons reflect relative change, not raw volume or units.
panel_a_raw <- bind_rows(
  food_beverages |>
    select(year, beer, sugar, ethyl_alcohol_1) |>
    pivot_longer(-year, names_to = "series", values_to = "value"),
  textiles |>
    select(year, total_textiles, raw_silk) |>
    pivot_longer(-year, names_to = "series", values_to = "value")
)

panel_a_indexed <- panel_a_raw |>
  filter(!is.na(value)) |>
  filter(series %in% c("total_textiles", "raw_silk")) |>
  group_by(series) |>
  mutate(
    base_value = first(value),
    base_year  = first(year),
    indexed    = value / base_value * 100
  ) |>
  ungroup() |>
  mutate(
    series_label = case_when(
      series == "total_textiles" ~ "Total Textiles",
      series == "raw_silk" ~ "Raw Silk"
    ),
    color_role = case_when(
      series == "raw_silk" ~ "decline",
      series == "total_textiles" ~ "core"
    )
  )

### |- Panel B: Average ship weight (derived metric) ----
# avg_ship_weight = ships_weight / ships_launched
# A proxy for industrial capability: fewer but heavier ships = upgrading

panel_b <- transport |>
  filter(!is.na(ships_weight), !is.na(ships_launched), ships_launched > 0) |>
  mutate(avg_ship_weight = ships_weight / ships_launched) |>
  select(year, avg_ship_weight, ships_launched, ships_weight)

# Identify annotatable inflection points for Panel B narrative
panel_b_annotations <- panel_b |>
  summarise(
    early_median  = median(avg_ship_weight[year <= 1900], na.rm = TRUE),
    late_median = median(avg_ship_weight[year >= 1960], na.rm = TRUE),
    peak_year = year[which.max(avg_ship_weight)],
    peak_val = max(avg_ship_weight, na.rm = TRUE)
  )
```

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

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

### |- plot aesthetics ----
colors <- get_theme_colors(
    palette = list(
        "rise"    = "#722F37", 
        "decline" = "#4A6FA5", 
        "core"    = "#C26A3D", 
        "neutral" = "gray75"   
    )
)

### |- titles and captions ----
title_text    <- str_glue("Italy industrialized unevenly")

subtitle_a    <- str_glue(
    "Indexed to first available year (= 100).",
    " Silk declined; textiles rose and stabilized.<br>",
    "<span style='color:{colors$palette$decline}'>Raw Silk</span>: Italy's oldest fiber industry, in long retreat;",
    " <span style='color:{colors$palette$core}'>Total Textiles</span>: postwar manufacturing anchor."
)

title_b <- str_glue("Ships became fewer but heavier")
subtitle_b <- str_glue(
    "Average gross tonnage per ship launched — a proxy for industrial capability."
)

caption_text  <- create_social_caption(
    tt_year = 2026,
    tt_week = 18,
    source_text = "ISTAT — Sommari di statistiche storiche (1861–1985)"
)

caption_b_note <- str_glue(
    "Note: Before 1951, values refer to fiscal years; from 1951 onward, calendar years."
)

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

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

weekly_theme <- extend_weekly_theme(
  base_theme,
  theme(
    plot.title = element_text(
      face = "bold", family = fonts$title,
      size = rel(1.3), hjust = 0, margin = margin(b = 4)
    ),
    plot.subtitle = element_markdown(
      family = fonts$text,
      size = rel(0.85), hjust = 0,
      lineheight = 1.3, margin = margin(b = 10)
    ),
    plot.caption = element_markdown(
      family = fonts$text,
      size   = rel(0.7), hjust = 0,
      color  = "gray50", margin = margin(t = 10)
    ),
    axis.title = element_text(
      family = fonts$text, size = rel(0.8), color = "gray40"
    ),
    axis.text = element_text(
      family = fonts$text, size = rel(0.75), color = "gray50"
    ),
    panel.grid.major.y = element_line(color = "gray92", linewidth = 0.3),
    panel.grid.major.x = element_blank(),
    panel.grid.minor = element_blank(),
    axis.ticks = element_blank(),
    strip.text = element_blank()
  )
)

theme_set(weekly_theme)
```

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

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

### |- Panel A: Indexed divergence ----

role_colors <- c(
  "decline" = colors$palette$decline,
  "core"    = colors$palette$core
)

role_linewidth <- c(
  "decline" = 1.4,
  "core"    = 1.4
)

role_alpha <- c(
  "decline" = 1,
  "core"    = 1
)

p_a <- panel_a_indexed |>
  ggplot(aes(
    x = year, y = indexed,
    group = series_label,
    color = color_role,
    linewidth = color_role,
    alpha = color_role
  )) +
  annotate("rect",
    xmin = 1915, xmax = 1918,
    ymin = -Inf, ymax = Inf,
    fill = "gray80", alpha = 0.10
  ) +
  annotate("rect",
    xmin = 1940, xmax = 1945,
    ymin = -Inf, ymax = Inf,
    fill = "gray80", alpha = 0.10
  ) +
  geom_vline(
    xintercept = 1951,
    linetype   = "dotted",
    linewidth  = 0.3,
    color      = "gray65"
  ) +
  annotate(
    "text",
    x = 1952, y = Inf,
    label = "Calendar-year reporting begins",
    hjust = 0, vjust = 1.5,
    size = 2.5,
    family = fonts$text,
    color = "gray45"
  ) +
  # Geoms
  geom_hline(
    yintercept = 100, linetype = "dashed",
    linewidth = 0.3, color = "gray60"
  ) +
  geom_line(lineend = "round") +
  geom_text(
    data = panel_a_indexed |>
      group_by(series_label, color_role) |>
      slice_max(year, n = 1) |>
      ungroup() |>
      mutate(
        y_nudge = case_when(
          series_label == "Raw Silk" ~ -12,
          series_label == "Total Textiles" ~ 8,
          TRUE ~ 0
        ),
        y_final = indexed + y_nudge
      ),
    aes(x = year, y = y_final, label = series_label, color = color_role),
    hjust = -0.12, size = 2.8,
    family = fonts$text,
    fontface = "bold",
    show.legend = FALSE
  ) +
  # Scales
  scale_color_manual(values = role_colors, guide = "none") +
  scale_linewidth_manual(values = role_linewidth, guide = "none") +
  scale_alpha_manual(values = role_alpha, guide = "none") +
  scale_x_continuous(
    breaks = seq(1870, 1980, by = 20),
    expand = expansion(mult = c(0.02, 0.18))
  ) +
  scale_y_continuous(
    labels = label_number(suffix = "×", scale = 0.01, accuracy = 0.1),
    breaks = c(0, 0.5, 1, 1.5, 2, 2.5, 3) * 100,
    limits = c(0, NA)
  ) +
  coord_cartesian(clip = "off") +
  # annotate
  annotate("text",
    x = 1916.5, y = Inf,
    label = "WWI", hjust = 0.5, vjust = 2,
    size = 2.3, color = "gray50", family = fonts$text
  ) +
  annotate("text",
    x = 1942.5, y = Inf,
    label = "WWII", hjust = 0.5, vjust = 2,
    size = 2.3, color = "gray50", family = fonts$text
  ) +
  annotate("text",
    x = 1944, y = 0.35,
    label = "WWII collapse",
    hjust = 0.5, vjust = 1,
    size = 2.4, color = "gray45",
    family = fonts$text
  ) +
  # Labs
  labs(
    subtitle = subtitle_a,
    x = NULL,
    y = "Production index"
  )

### |- Panel B: Ship sophistication ----

# Find key annotation years
peak_row <- panel_b |> slice_max(avg_ship_weight, n = 1)
early_row <- panel_b |>
  filter(year <= 1890) |>
  slice_min(year, n = 1)

p_b <- panel_b |>
  ggplot(aes(x = year, y = avg_ship_weight)) +
  # Geoms
  geom_line(
    color     = colors$palette$core,
    linewidth = 0.85,
    lineend   = "round"
  ) +
  # Annotate
  annotate("text",
    x = 1878, y = 1800,
    label = "Many small ships\n(capacity era)",
    hjust = 0.5, vjust = 0,
    size = 2.6, color = "gray45",
    family = fonts$text, lineheight = 1.2
  ) +
  annotate("point",
    x = peak_row$year, y = peak_row$avg_ship_weight,
    color = colors$palette$rise, size = 2.2
  ) +
  annotate("text",
    x = peak_row$year + 2, y = peak_row$avg_ship_weight + 2200,
    label = glue("{scales::comma(round(peak_row$avg_ship_weight))} tons/ship"),
    hjust = 0, vjust = 0,
    size = 2.4, color = "gray35",
    family = fonts$text, lineheight = 1.2
  ) +
  annotate("text",
    x = 1965, y = peak_row$avg_ship_weight * 0.55,
    label = "Fewer, heavier ships\n(capability era)",
    hjust = 0.5, vjust = 1,
    size = 2.6, color = "gray45",
    family = fonts$text, lineheight = 1.2
  ) +

  # Scales
  scale_x_continuous(breaks = seq(1860, 1980, by = 20)) +
  scale_y_continuous(labels = label_comma()) +
  # Scales
  labs(
    title = title_b,
    subtitle = subtitle_b,
    x = NULL,
    y = "Avg. gross tonnage per ship (tons)",
    caption = glue("{caption_b_note}<br>{caption_text}")
  ) +
  # Theme
  theme(
    plot.title = element_text(
      face   = "bold",
      family = fonts$title,
      size   = rel(1.05),
      hjust  = 0,
      margin = margin(b = 3)
    ),
    plot.subtitle = element_markdown(
      family   = 'sans',
      size     = rel(0.8),
      hjust    = 0,
      color    = "gray40",
      margin   = margin(b = 8)
    )
  )

### |- Combine plots ----

p_final <- (p_a / p_b) +
  plot_layout(heights = c(1.55, 1)) +
  plot_annotation(
    title = title_text,
    theme = theme(
      plot.title = element_text(
        face   = "bold",
        family = fonts$title,
        size   = rel(1.6),
        hjust  = 0,
        margin = margin(b = 6)
      ),
      plot.margin = margin(t = 16, r = 20, b = 12, l = 16)
    )
  )

```

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

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

### |-  plot image ----  
save_plot_patchwork(
  plot = p_final, 
  type = "tidytuesday", 
  year = 2026, 
  week = 18, 
  width  = 11,
  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 [`tt_2026_18.qmd`](https://github.com/poncest/personal-website/blob/master/data_visualizations/TidyTuesday/2026/tt_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 Source:**
    -   TidyTuesday 2026 Week 18: [Italian Industrial Production](https://github.com/rfordatascience/tidytuesday/blob/main/data/2026/2026-05-05readme.md)

:::


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