• 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

Coal falls. Renewables rise.

  • Show All Code
  • Hide All Code

  • View Source

China’s energy pivot is rewriting the power equation. Share of electricity generation · 2000–2023

30DayChartChallenge
Data Visualization
R Programming
2026
A South China Morning Post–style timeseries tracking China’s electricity mix from 2000 to 2023. Coal share peaked at 81% in 2007 and has fallen steadily since; renewables have climbed from 16% to 31%, accelerating sharply after 2015. Built with ggplot2 and ggtext on a dark navy canvas with direct annotation replacing a legend.
Author

Steven Ponce

Published

April 24, 2026

Figure 1: Line chart on a dark navy background showing China’s electricity generation mix from 2000 to 2023. Two lines diverge over time: Coal (muted blue-grey) falls from 78% in 2000 to 61% in 2023, peaking at 81% in 2007; renewables (gold) rise from 16% to 31%, accelerating sharply after 2015 when national solar targets were set. Title reads “Coal falls. Renewables rise.” A callout notes that in 2023, China installed more solar capacity than the US has ever built.

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

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

energy_raw <- read_csv(here("data/30DayChartChallenge/2026/owid-energy-data.csv"),
  show_col_types = FALSE
)
```

3. Examine the Data

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

glimpse(energy_raw)

### |- compare hydro-inclusive vs. new-renewables (solar + wind) ----
energy_raw |>
  filter(country == "China", year >= 2000) |>
  select(
    year,
    coal_share_elec,
    renewables_share_elec,
    solar_share_elec,
    wind_share_elec
  ) |> 
  mutate(solar_wind = solar_share_elec + wind_share_elec) |>
  filter(year %in% c(2000, 2005, 2010, 2015, 2020, 2023)) |>
  select(year, coal_share_elec, renewables_share_elec, solar_wind) 
```

4. Tidy Data

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

### |- filter China, 2000–2023, pivot long ----
china <- energy_raw |>
  filter(country == "China", year >= 2000, year <= 2023) |>
  select(
    year,
    coal      = coal_share_elec,
    renewable = renewables_share_elec
  ) |>
  filter(!is.na(coal), !is.na(renewable)) |>
  pivot_longer(
    cols      = c(coal, renewable),
    names_to  = "source",
    values_to = "share"
  ) |>
  mutate(
    source = factor(source, levels = c("renewable", "coal"))
  )

### |- confirm 2023 endpoint values ----
val_coal_2023  <- china |>
  filter(year == 2023, source == "coal") |>
  pull(share) |>
  round(1)

val_renew_2023 <- china |>
  filter(year == 2023, source == "renewable") |>
  pull(share) |>
  round(1)

### |- find coal peak year ----
coal_peak <- china |>
  filter(source == "coal") |>
  slice_max(share, n = 1)

coal_peak_year <- coal_peak$year
coal_peak_val  <- round(coal_peak$share, 1)
```

5. Visualization Parameters

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

### |- plot aesthetics ----
colors <- get_theme_colors(palette = list(
  bg_color     = "#0D1B2A",
  solar_gold   = "#F4A932", 
  coal_blue    = "#6A80A0",   
  text_white   = "#FFFFFF",
  text_muted   = "#8A98A8",
  text_sub     = "#B0B8C4",
  grid_color    = "#1A2E42",
  accent_coral = "#E8503A"   
))

bg_color     <- colors$palette$bg_color
solar_gold   <- colors$palette$solar_gold
coal_blue    <- colors$palette$coal_blue
text_white   <- colors$palette$text_white
text_muted   <- colors$palette$text_muted
text_sub     <- colors$palette$text_sub
grid_color   <- colors$palette$grid_color
accent_coral <- colors$palette$accent_coral
col_renew <- solar_gold
col_coal  <- coal_blue


### |- titles and caption ----
title_text <- glue(
  "<span style='font-weight:900; color:{coal_blue};'>Coal falls.&nbsp;</span>",
  "<span style='font-weight:900; color:{solar_gold};'> Renewables rise.</span>"
)

subtitle_text <- glue(
  "<span style='font-size:12pt; font-weight:400; color:{text_sub};'>",
  "China's energy pivot is rewriting the power equation<br>",
  "Share of electricity generation · 2000–2023",
  "</span>"
)

caption_text  <- create_dcc_caption(
  dcc_year    = 2026,
  dcc_day     = 24,
  source_text = "Our World in Data · OWID Energy Dataset (BP / Ember)"
)

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

6. Plot

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

### |- main plot ----
p <- china |>
  ggplot(aes(x = year, y = share, color = source, group = source)) +

  # Geom
  geom_hline(
    yintercept = seq(0, 80, by = 20),
    color = grid_color,
    linewidth = 0.25
  ) +
  geom_line(
    data = china |> filter(source == "renewable"),
    linewidth = 1.9,
    alpha = 1.0
  ) +
  geom_line(
    data = china |> filter(source == "coal"),
    linewidth = 1.3,
    alpha = 0.60
  ) +
  geom_point(
    data = china |> filter(year == 2000),
    size = 3.5,
    shape = 21,
    fill = bg_color,
    stroke = 1.8
  ) +
  geom_point(
    data = china |> filter(year == 2023),
    size = 3.5,
    shape = 21,
    fill = bg_color,
    stroke = 1.8
  ) +

  # Annotate
  annotate(
    "segment",
    x = coal_peak_year, xend = coal_peak_year,
    y = 0, yend = coal_peak_val - 3,
    color = accent_coral,
    linewidth = 0.5,
    linetype = "dotted"
  ) +
  annotate(
    "text",
    x = coal_peak_year - 0.3,
    y = coal_peak_val - 5,
    label = glue("Coal peak\n{coal_peak_year}: {coal_peak_val}%"),
    hjust = 1,
    size = 2.9,
    color = accent_coral,
    family = fonts$text,
    lineheight = 1.1
  ) +
  annotate(
    "segment",
    x = 2015, xend = 2015,
    y = 0, yend = 30,
    color = "#D8E4EE",
    linewidth = 0.45,
    linetype = "dotted"
  ) +
  annotate(
    "text",
    x = 2015.4,
    y = 32,
    label = "2015: National\nsolar targets set",
    hjust = 0,
    size = 2.9,
    color = "#D8E4EE",
    family = fonts$text,
    lineheight = 1.1
  ) +
  annotate(
    "text",
    x = 2019.8,
    y = 44,
    label = "2023: China installs more solar\nthan the US has ever built",
    hjust = 0,
    vjust = 0,
    size = 3.0,
    color = solar_gold,
    family = fonts$text,
    lineheight = 1.2,
    fontface = "bold"
  ) +
  annotate(
    "text",
    x = 2023.6,
    y = c(val_renew_2023, val_coal_2023),
    label = c(
      glue("Renewables\n{val_renew_2023}%"),
      glue("Coal\n{val_coal_2023}%")
    ),
    hjust = 0,
    vjust = 0.5,
    size = 3.2,
    color = c(col_renew, col_coal),
    family = fonts$text,
    lineheight = 1.15
  ) +

  # Scales
  scale_color_manual(
    values = c("renewable" = col_renew, "coal" = col_coal)
  ) +
  scale_x_continuous(
    breaks = c(2000, 2005, 2010, 2015, 2020, 2023),
    expand = expansion(mult = c(0.03, 0.24))
  ) +
  scale_y_continuous(
    limits = c(0, 90),
    breaks = seq(0, 80, by = 20),
    labels = \(x) glue("{x}%"),
    expand = expansion(mult = c(0.01, 0.04))
  ) +

  # Labs
  labs(
    title = title_text,
    subtitle = subtitle_text,
    caption = caption_text,
    x = NULL,
    y = NULL
  ) +

  # Theme
  theme_void() +
  theme(
    # canvas
    plot.background = element_rect(fill = bg_color, color = NA),
    panel.background = element_rect(fill = bg_color, color = NA),
    plot.title = element_markdown(
      family = fonts$title,
      size = 28,
      color = text_white,
      hjust = 0,
      lineheight = 1.1,
      margin = margin(t = 10, b = 6)
    ),
    plot.subtitle = element_markdown(
      family = fonts$text,
      size = 10,
      color = text_sub,
      hjust = 0,
      lineheight = 1.4,
      margin = margin(b = 22)
    ),
    plot.caption = element_markdown(
      family = fonts$text,
      size = 6.5,
      color = "#5A6878",
      hjust = 1,
      margin = margin(t = 14)
    ),
    axis.text.x = element_text(
      family = fonts$text,
      size   = 9,
      color  = text_muted,
      margin = margin(t = 6)
    ),
    axis.text.y = element_text(
      family = fonts$text,
      size = 8,
      color = text_muted,
      hjust = 1
    ),
    axis.line = element_blank(),
    axis.ticks = element_blank(),
    panel.grid = element_blank(),
    legend.position = "none",
    plot.margin = margin(t = 20, r = 16, b = 16, l = 20)
  )
```

7. Save

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

### |-  plot image ----  
save_plot(
  p,
  type = "30daychartchallenge",
  year = 2026,
  day = 24,
  width = 6,
  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      glue_1.8.0      scales_1.4.0    janitor_2.2.1  
 [5] showtext_0.9-8  showtextdb_3.0  sysfonts_0.8.9  ggtext_0.1.2   
 [9] lubridate_1.9.5 forcats_1.0.1   stringr_1.6.0   dplyr_1.2.1    
[13] purrr_1.2.2     readr_2.2.0     tidyr_1.3.2     tibble_3.3.1   
[17] ggplot2_4.0.2   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] vctrs_0.7.3        tools_4.5.3        generics_0.1.4     curl_7.0.0        
 [9] parallel_4.5.3     gifski_1.32.0-2    pacman_0.5.1       pkgconfig_2.0.3   
[13] RColorBrewer_1.1-3 S7_0.2.1           lifecycle_1.0.5    compiler_4.5.3    
[17] farver_2.1.2       textshaping_1.0.5  codetools_0.2-20   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.9.1       commonmark_2.0.0  
[29] tidyselect_1.2.1   digest_0.6.39      stringi_1.8.7      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     withr_3.0.2        bit64_4.6.0-1      timechange_0.4.0  
[41] rmarkdown_2.31     bit_4.6.0          otel_0.2.0         ragg_1.5.2        
[45] hms_1.1.4          evaluate_1.0.5     knitr_1.51         markdown_2.0      
[49] rlang_1.2.0        gridtext_0.1.6     Rcpp_1.1.1         xml2_1.5.2        
[53] svglite_2.2.2      rstudioapi_0.18.0  vroom_1.7.1        jsonlite_2.0.0    
[57] 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_24.qmd.

For the full repository, click here.

10. References

TipExpand for References
  1. Data Sources:
    • Hannah Ritchie, Pablo Rosado, and Max Roser (2024). Energy. Published online at OurWorldInData.org. Retrieved from: https://ourworldindata.org/energy

    • Underlying data sourced from BP Statistical Review of World Energy and Ember Global Electricity Review, as compiled by Our World in Data. Dataset: https://github.com/owid/energy-data

  2. Chart Inspiration:
    • South China Morning Post Infographics. Retrieved from: https://www.scmp.com/infographics

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 = {Coal Falls. {Renewables} Rise.},
  date = {2026-04-24},
  url = {https://stevenponce.netlify.app/data_visualizations/30DayChartChallenge/2026/30dcc_2026_24.html},
  langid = {en}
}
For attribution, please cite this work as:
Ponce, Steven. 2026. “Coal Falls. Renewables Rise.” April 24, 2026. https://stevenponce.netlify.app/data_visualizations/30DayChartChallenge/2026/30dcc_2026_24.html.
Source Code
---
title: "Coal falls. Renewables rise."
subtitle: "China's energy pivot is rewriting the power equation. Share of electricity generation · 2000–2023"
description: "A South China Morning Post–style timeseries tracking China's electricity mix from 2000 to 2023. Coal share peaked at 81% in 2007 and has fallen steadily since; renewables have climbed from 16% to 31%, accelerating sharply after 2015. Built with ggplot2 and ggtext on a dark navy canvas with direct annotation replacing a legend."
date: "2026-04-24" 
author:
  - name: "Steven Ponce"
    url: "https://stevenponce.netlify.app"
citation:
  url: "https://stevenponce.netlify.app/data_visualizations/30DayChartChallenge/2026/30dcc_2026_24.html"
categories: ["30DayChartChallenge", "Data Visualization", "R Programming", "2026"]
tags: [
  "30DayChartChallenge",
  "Timeseries",
  "SCMP",
  "Theme Day",
  "Line Chart",
  "Energy",
  "China",
  "Renewables",
  "Coal",
  "OWID",
  "ggplot2",
  "ggtext",
  "Dark Theme",
  "Editorial"
]
image: "thumbnails/30dcc_2026_24.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
---

![Line chart on a dark navy background showing China's electricity generation mix from 2000 to 2023. Two lines diverge over time: Coal (muted blue-grey) falls from 78% in 2000 to 61% in 2023, peaking at 81% in 2007; renewables (gold) rise from 16% to 31%, accelerating sharply after 2015 when national solar targets were set. Title reads "Coal falls. Renewables rise." A callout notes that in 2023, China installed more solar capacity than the US has ever built.](30dcc_2026_24.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
  )
})

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

energy_raw <- read_csv(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(energy_raw)

### |- compare hydro-inclusive vs. new-renewables (solar + wind) ----
energy_raw |>
  filter(country == "China", year >= 2000) |>
  select(
    year,
    coal_share_elec,
    renewables_share_elec,
    solar_share_elec,
    wind_share_elec
  ) |> 
  mutate(solar_wind = solar_share_elec + wind_share_elec) |>
  filter(year %in% c(2000, 2005, 2010, 2015, 2020, 2023)) |>
  select(year, coal_share_elec, renewables_share_elec, solar_wind) 

```

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

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

### |- filter China, 2000–2023, pivot long ----
china <- energy_raw |>
  filter(country == "China", year >= 2000, year <= 2023) |>
  select(
    year,
    coal      = coal_share_elec,
    renewable = renewables_share_elec
  ) |>
  filter(!is.na(coal), !is.na(renewable)) |>
  pivot_longer(
    cols      = c(coal, renewable),
    names_to  = "source",
    values_to = "share"
  ) |>
  mutate(
    source = factor(source, levels = c("renewable", "coal"))
  )

### |- confirm 2023 endpoint values ----
val_coal_2023  <- china |>
  filter(year == 2023, source == "coal") |>
  pull(share) |>
  round(1)

val_renew_2023 <- china |>
  filter(year == 2023, source == "renewable") |>
  pull(share) |>
  round(1)

### |- find coal peak year ----
coal_peak <- china |>
  filter(source == "coal") |>
  slice_max(share, n = 1)

coal_peak_year <- coal_peak$year
coal_peak_val  <- round(coal_peak$share, 1)

```


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

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

### |- plot aesthetics ----
colors <- get_theme_colors(palette = list(
  bg_color     = "#0D1B2A",
  solar_gold   = "#F4A932", 
  coal_blue    = "#6A80A0",   
  text_white   = "#FFFFFF",
  text_muted   = "#8A98A8",
  text_sub     = "#B0B8C4",
  grid_color    = "#1A2E42",
  accent_coral = "#E8503A"   
))

bg_color     <- colors$palette$bg_color
solar_gold   <- colors$palette$solar_gold
coal_blue    <- colors$palette$coal_blue
text_white   <- colors$palette$text_white
text_muted   <- colors$palette$text_muted
text_sub     <- colors$palette$text_sub
grid_color   <- colors$palette$grid_color
accent_coral <- colors$palette$accent_coral
col_renew <- solar_gold
col_coal  <- coal_blue


### |- titles and caption ----
title_text <- glue(
  "<span style='font-weight:900; color:{coal_blue};'>Coal falls.&nbsp;</span>",
  "<span style='font-weight:900; color:{solar_gold};'> Renewables rise.</span>"
)

subtitle_text <- glue(
  "<span style='font-size:12pt; font-weight:400; color:{text_sub};'>",
  "China's energy pivot is rewriting the power equation<br>",
  "Share of electricity generation · 2000–2023",
  "</span>"
)

caption_text  <- create_dcc_caption(
  dcc_year    = 2026,
  dcc_day     = 24,
  source_text = "Our World in Data · OWID Energy Dataset (BP / Ember)"
)

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

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

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

### |- main plot ----
p <- china |>
  ggplot(aes(x = year, y = share, color = source, group = source)) +

  # Geom
  geom_hline(
    yintercept = seq(0, 80, by = 20),
    color = grid_color,
    linewidth = 0.25
  ) +
  geom_line(
    data = china |> filter(source == "renewable"),
    linewidth = 1.9,
    alpha = 1.0
  ) +
  geom_line(
    data = china |> filter(source == "coal"),
    linewidth = 1.3,
    alpha = 0.60
  ) +
  geom_point(
    data = china |> filter(year == 2000),
    size = 3.5,
    shape = 21,
    fill = bg_color,
    stroke = 1.8
  ) +
  geom_point(
    data = china |> filter(year == 2023),
    size = 3.5,
    shape = 21,
    fill = bg_color,
    stroke = 1.8
  ) +

  # Annotate
  annotate(
    "segment",
    x = coal_peak_year, xend = coal_peak_year,
    y = 0, yend = coal_peak_val - 3,
    color = accent_coral,
    linewidth = 0.5,
    linetype = "dotted"
  ) +
  annotate(
    "text",
    x = coal_peak_year - 0.3,
    y = coal_peak_val - 5,
    label = glue("Coal peak\n{coal_peak_year}: {coal_peak_val}%"),
    hjust = 1,
    size = 2.9,
    color = accent_coral,
    family = fonts$text,
    lineheight = 1.1
  ) +
  annotate(
    "segment",
    x = 2015, xend = 2015,
    y = 0, yend = 30,
    color = "#D8E4EE",
    linewidth = 0.45,
    linetype = "dotted"
  ) +
  annotate(
    "text",
    x = 2015.4,
    y = 32,
    label = "2015: National\nsolar targets set",
    hjust = 0,
    size = 2.9,
    color = "#D8E4EE",
    family = fonts$text,
    lineheight = 1.1
  ) +
  annotate(
    "text",
    x = 2019.8,
    y = 44,
    label = "2023: China installs more solar\nthan the US has ever built",
    hjust = 0,
    vjust = 0,
    size = 3.0,
    color = solar_gold,
    family = fonts$text,
    lineheight = 1.2,
    fontface = "bold"
  ) +
  annotate(
    "text",
    x = 2023.6,
    y = c(val_renew_2023, val_coal_2023),
    label = c(
      glue("Renewables\n{val_renew_2023}%"),
      glue("Coal\n{val_coal_2023}%")
    ),
    hjust = 0,
    vjust = 0.5,
    size = 3.2,
    color = c(col_renew, col_coal),
    family = fonts$text,
    lineheight = 1.15
  ) +

  # Scales
  scale_color_manual(
    values = c("renewable" = col_renew, "coal" = col_coal)
  ) +
  scale_x_continuous(
    breaks = c(2000, 2005, 2010, 2015, 2020, 2023),
    expand = expansion(mult = c(0.03, 0.24))
  ) +
  scale_y_continuous(
    limits = c(0, 90),
    breaks = seq(0, 80, by = 20),
    labels = \(x) glue("{x}%"),
    expand = expansion(mult = c(0.01, 0.04))
  ) +

  # Labs
  labs(
    title = title_text,
    subtitle = subtitle_text,
    caption = caption_text,
    x = NULL,
    y = NULL
  ) +

  # Theme
  theme_void() +
  theme(
    # canvas
    plot.background = element_rect(fill = bg_color, color = NA),
    panel.background = element_rect(fill = bg_color, color = NA),
    plot.title = element_markdown(
      family = fonts$title,
      size = 28,
      color = text_white,
      hjust = 0,
      lineheight = 1.1,
      margin = margin(t = 10, b = 6)
    ),
    plot.subtitle = element_markdown(
      family = fonts$text,
      size = 10,
      color = text_sub,
      hjust = 0,
      lineheight = 1.4,
      margin = margin(b = 22)
    ),
    plot.caption = element_markdown(
      family = fonts$text,
      size = 6.5,
      color = "#5A6878",
      hjust = 1,
      margin = margin(t = 14)
    ),
    axis.text.x = element_text(
      family = fonts$text,
      size   = 9,
      color  = text_muted,
      margin = margin(t = 6)
    ),
    axis.text.y = element_text(
      family = fonts$text,
      size = 8,
      color = text_muted,
      hjust = 1
    ),
    axis.line = element_blank(),
    axis.ticks = element_blank(),
    panel.grid = element_blank(),
    legend.position = "none",
    plot.margin = margin(t = 20, r = 16, b = 16, l = 20)
  )
```

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

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

### |-  plot image ----  
save_plot(
  p,
  type = "30daychartchallenge",
  year = 2026,
  day = 24,
  width = 6,
  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_24.qmd`](https://github.com/poncest/personal-website/blob/master/data_visualizations/TidyTuesday/2026/30dcc_2026_24.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:**
   - Hannah Ritchie, Pablo Rosado, and Max Roser (2024).
     Energy. Published online at OurWorldInData.org.
     Retrieved from: https://ourworldindata.org/energy

   - Underlying data sourced from BP Statistical Review of World Energy
     and Ember Global Electricity Review, as compiled by Our World in Data.
     Dataset: https://github.com/owid/energy-data

2. **Chart Inspiration:**
   - South China Morning Post Infographics.
     Retrieved from: https://www.scmp.com/infographics
:::


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