---
title: "Energy Transitions Are Not Smooth"
subtitle: "Year-over-year change in renewable electricity share (percentage points), 1991–2023. Frequent reversals and uneven gains reveal how unpredictable the path to clean energy can be."
description: "A faceted bar chart examining year-over-year volatility in renewable electricity share across five countries from 1991 to 2023. Five transition archetypes — selected to contrast stable versus volatile paths — reveal that even countries making real progress experience frequent reversals. Built with ggplot2 using diverging color encoding and small multiples to make instability immediately legible across panels."
date: "2026-04-27"
author:
- name: "Steven Ponce"
url: "https://stevenponce.netlify.app"
citation:
url: "https://stevenponce.netlify.app/data_visualizations/30DayChartChallenge/2026/30dcc_2026_27.html"
categories: ["30DayChartChallenge", "2026"]
tags: [
"30DayChartChallenge",
"Uncertainties",
"Animation",
"Energy Transition",
"Renewable Energy",
"Faceted Chart",
"Bar Chart",
"Small Multiples",
"Time Series",
"Volatility",
"Climate",
"OWID",
"ggplot2"
]
image: "thumbnails/30dcc_2026_27.png"
format:
html:
toc: true
toc-depth: 5
code-link: true
code-fold: true
code-tools: true
code-summary: "Show code"
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, here
)
})
### |- 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
### |- observed CO₂: read from local cache ----
raw_data <- read_csv(
here::here("data/30DayChartChallenge/2026/owid-energy-data.csv"),
show_col_types = FALSE
)
```
#### [3. Examine the Data]{.smallcaps}
```{r}
#| label: examine
#| include: true
#| eval: true
#| results: 'hide'
#| warning: false
glimpse(raw_data)
```
#### [4. Tidy Data]{.smallcaps}
```{r}
#| label: tidy
#| warning: false
selected_countries <- c(
"Denmark",
"Brazil",
"Germany",
"Spain",
"Australia"
)
# Archetype labels —
archetype_map <- tribble(
~country, ~archetype, ~profile,
"Denmark", "Wind-driven volatility", "moderate",
"Brazil", "Gradual mover", "smooth",
"Germany", "Managed transition", "moderate",
"Spain", "Boom & reversal", "volatile",
"Australia", "Political whipsaw", "volatile"
)
### |- filter and compute delta ----
df_clean <- raw_data |>
filter(
country %in% selected_countries,
year >= 1991,
year <= 2023
) |>
select(country, year, renewables_share_elec) |>
mutate(renewables_share_elec = as.numeric(renewables_share_elec)) |>
filter(!is.na(renewables_share_elec)) |>
arrange(country, year) |>
group_by(country) |>
mutate(
delta_renew = renewables_share_elec - lag(renewables_share_elec)
) |>
filter(!is.na(delta_renew)) |>
ungroup()
### |- join archetype metadata ----
df_plot <- df_clean |>
left_join(archetype_map, by = "country") |>
mutate(
country = factor(country, levels = c(
"Denmark", "Brazil", "Germany", "Spain", "Australia"
)),
# direction for coloring bars/fill
direction = if_else(delta_renew >= 0, "positive", "negative")
)
### |- per-country volatility stats (for annotation) ----
df_stats <- df_plot |>
group_by(country, archetype, profile) |>
summarise(
sd_delta = round(sd(delta_renew, na.rm = TRUE), 1),
mean_delta = round(mean(delta_renew, na.rm = TRUE), 1),
n_negative = sum(delta_renew < 0),
.groups = "drop"
)
### |- strip label: country + archetype ----
strip_labels <- archetype_map |>
mutate(label = paste0(country, "\n", archetype)) |>
select(country, label) |>
deframe()
### |- volatility annotation per panel ----
df_annot <- df_stats |>
mutate(
label = paste0("SD = ", sd_col <- sd_delta, " pp"),
x_pos = 2022,
y_pos = Inf
)
```
#### [5. Visualization Parameters]{.smallcaps}
```{r}
#| label: params
#| include: true
#| warning: false
### |- plot aesthetics ----
colors <- get_theme_colors(
palette = list(
"background" = "#F5F3EE",
"text" = "#2C2C2C",
"subtext" = "#5C5C5C",
"grid" = "#E8E5DF",
"positive" = "#2E6B9E",
"negative" = "#8B3030",
"zero_line" = "#9A9591"
)
)
bg_col <- colors$palette$background
text_col <- colors$palette$text
sub_col <- colors$palette$subtext
grid_col <- colors$palette$grid
pos_col <- colors$palette$positive
neg_col <- colors$palette$negative
zero_col <- colors$palette$zero_line
### |- titles and caption ----
title_text <- "Energy Transitions Are Not Smooth"
subtitle_text <- paste0(
"Year-over-year change in renewable electricity share (percentage points), 1991–2023.<br>",
"Frequent reversals and uneven gains reveal how unpredictable the path to clean energy can be."
)
caption_text <- create_dcc_caption(
dcc_year = 2026,
dcc_day = 27,
source_text = "Our World in Data | Energy Mix"
)
### |- fonts ----
setup_fonts()
fonts <- get_font_families()
### |- base theme ----
base_theme <- create_base_theme(colors)
weekly_theme <- extend_weekly_theme(
base_theme,
theme(
plot.background = element_rect(fill = bg_col, color = NA),
panel.background = element_rect(fill = bg_col, color = NA),
# minimal grid — only horizontal reference
panel.grid.major.y = element_line(color = grid_col, linewidth = 0.3),
panel.grid.major.x = element_blank(),
panel.grid.minor = element_blank(),
# facet strips — country name + archetype label
strip.background = element_rect(fill = bg_col, color = NA),
strip.text = element_text(
family = fonts$text,
face = "bold",
size = 9,
color = text_col,
hjust = 0,
margin = margin(b = 4)
),
# axes
axis.title = element_text(color = sub_col, size = 9, family = fonts$text),
axis.text.x = element_text(color = sub_col, size = 7.5, family = fonts$text),
axis.text.y = element_text(color = sub_col, size = 7.5, family = fonts$text),
axis.ticks = element_blank(),
# panel spacing
panel.spacing.x = unit(1.2, "lines"),
plot.title = element_text(
family = fonts$title, face = "bold",
size = 18, color = text_col,
margin = margin(b = 6)
),
plot.subtitle = element_markdown(
family = fonts$text, size = 9.5, color = sub_col,
lineheight = 1.45, margin = margin(b = 14)
),
plot.caption = element_markdown(
family = fonts$text, size = 7.5, color = sub_col,
hjust = 0, margin = margin(t = 12)
),
plot.margin = margin(20, 20, 14, 20)
)
)
theme_set(weekly_theme)
```
#### [6. Plot]{.smallcaps}
```{r}
#| label: plot
#| warning: false
### |- main plot ----
p <- ggplot(df_plot, aes(x = year, y = delta_renew)) +
# Geoms
geom_hline(
yintercept = 0,
color = zero_col,
linewidth = 0.6,
linetype = "solid"
) +
geom_col(
aes(fill = direction),
width = 0.75
) +
# Facet
facet_wrap(
~country,
nrow = 1,
labeller = labeller(country = strip_labels)
) +
# Scales
scale_fill_manual(
values = c("positive" = pos_col, "negative" = neg_col)
) +
scale_x_continuous(
breaks = c(2000, 2010, 2020),
labels = c("2000", "'10", "'20")
) +
scale_y_continuous(
name = "Δ Renewable share (pp)",
labels = label_number(suffix = "pp", style_positive = "plus")
) +
guides(fill = "none") +
# Labs
labs(
title = title_text,
subtitle = subtitle_text,
caption = caption_text,
x = NULL
)
```
#### [7. Save]{.smallcaps}
```{r}
#| label: save
#| warning: false
### |- plot image ----
save_plot(
p,
type = "30daychartchallenge",
year = 2026,
day = 27,
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_27.qmd`](https://github.com/poncest/personal-website/blob/master/data_visualizations/TidyTuesday/2026/30dcc_2026_27.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:**
- Ritchie, H., Rosado, P., & Roser, M. (2024). *Energy Mix.*
Our World in Data. Retrieved from: https://ourworldindata.org/energy-mix
- Underlying data: Our World in Data Energy Dataset (owid-energy-data.csv).
Retrieved from: https://github.com/owid/energy-data
:::
#### [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)
:::