Skip to main content

Replicating Graphs #1: OWID

Life Satisfaction and GDP per capita
r
dataviz
replication
Published

November 30, 2026

Original Graph: OWID

Description: Correlation between GDP per capita and self-reported happiness.

Data: World Bank and World Happiness Report

Loading Packages and Data

Code
library(pacman)

pacman::p_load(jsonlite, dplyr, tidyverse, janitor,
               ggrepel, systemfonts, ragg)

The data is available as a CSV file at the OWID website:

Code
df <- read.csv(
  "https://ourworldindata.org/grapher/gdp-vs-happiness.csv?v=1&csvType=full&useColumnShortNames=true"
)

Now, we can use the janitor package to tidy it a bit:

Code
data <- df |>
  janitor::clean_names() |>
  rename(
    life_satisfaction = cantril_ladder_score,
    gdppc = ny_gdp_pcap_pp_kd
  ) |>
  mutate(
    owid_region = na_if(trimws(owid_region), "")
  ) |>
  filter(
    !is.na(gdppc),
    !is.na(life_satisfaction),
    !is.na(owid_region),
    gdppc > 0
  ) |>
  group_by(entity) |>
  filter(year == max(year)) |>
  ungroup() |>
  mutate(gdppc = log10(gdppc)) |>
  select(entity, year, gdppc, life_satisfaction, owid_region)

The Plot

1. Bubbles

The plot shows each country as bubble. The position of each bubble shows the country’s GDP per capita and average life satisfaction, and its colors correspond to their continent.

Code
ggplot(data, aes(x = gdppc, y = life_satisfaction)) +
  geom_point(
    aes(fill = owid_region),
    color = "#A5A9A9",
    alpha = 0.8,
    shape = 21,
    size = 2)

Country highlights

I had AI scan the image and build a vector:

Code
sel_countries <- c(
  "Costa Rica",
  "Belize",
  "Brazil",
  "Argentina",
  "Australia",
  "Ireland",
  "Estonia",
  "Bahrain",
  "Hong Kong",
  "Tajikistan",
  "Honduras",
  "Bolivia",
  "Laos",
  "Algeria",
  "Albania",
  "Bulgaria",
  "Mozambique",
  "Cameroon",
  "Iraq",
  "Iran",
  "Azerbaijan",
  "Bangladesh",
  "Ukraine",
  "Sri Lanka",
  "Botswana",
  "Zimbabwe",
  "Lebanon",
  "Benin",
  "Congo",
  "DR Congo",
  "Chad",
  "Liberia",
  "Burundi",
  "Malawi",
  "Haiti",
  "Afghanistan"
)

Now we create the highlight dataframe with the countries we want to label and save the ggplot so we do not have to repeat the entire code again:

Code
highlight <- data |>
  filter(entity %in% sel_countries)

base <- ggplot(data, aes(x = gdppc, y = life_satisfaction)) +
  geom_point(
    aes(fill = owid_region),
    color = "#A5A9A9",
    alpha = 0.8,
    shape = 21
  ) +
  ggrepel::geom_text_repel(
    data = highlight,
    aes(
      x = gdppc,
      y = life_satisfaction,
      label = entity,
      color = owid_region
    ),
    size = 3
  )

Colors

Code
colors <- c(
  "Africa" = "#A2559C",
  "Asia" = "#00847E",
  "Europe" = "#4C6A9C",
  "North America" = "#E56E5A",
  "Oceania" = "#9A5129",
  "South America" = "#883039"
)

Scales

The x axis is in a logarithmic scale with a comma and dollar sign, while the y axis is a simple 2 to 7 integers.

Code
xbreaks <- log10(c(
  1000,
  2000,
  5000,
  10000,
  20000,
  50000,
  100000
))

xlabels <- paste0(
  "$",
  format(
    c(1000, 2000, 5000, 10000, 20000, 50000, 100000),
    big.mark = ",",
    scientific = FALSE
  )
)

base <- base +
  #> Adds labels to the log scale
  scale_x_continuous(breaks = xbreaks, labels = xlabels) +
  #> Adds labels to the y-axis scale
  scale_y_continuous(breaks = 2:7) +
  #> Adds colors to the bubbles and text labels
  scale_fill_manual(name = "", values = colors) +
  scale_color_manual(name = "", values = colors) +
  #> Removes the size and color legend
  guides(
    color = "none",
    size = "none",
    #> Override default behaviour to get solid colors
    fill = guide_legend(override.aes = list(shape = 22, alpha = 1))
  )

base

Almost there!

Text

First, let’s just verify how the title, subtitle, and caption looks like:

Code
title <- "Self-reported life satisfaction vs. GDP per capita"

subtitle <- paste(
  "Self-reported life satisfaction is measured on a scale ranging from 0-10,",
  "where 10 is the highest possible life satisfaction.",
  "GDP per capita is adjusted for inflation and differences in living costs between countries."
)

caption <- paste(
  "Data source: Wellbeing Research Centre (2026);",
  "Eurostat, OECD, IMF, and World Bank (2026)"
)

base <- base +
  labs(
    title = title,
    subtitle = subtitle,
    x = "GDP per capita",
    y = "Life satisfaction (0-10)",
    caption = caption
  )

base

Theme

Code
base <- base +
  labs(
    title = title,
    subtitle = subtitle,
    x = "GDP per capita",
    y = "Life satisfaction (0-10)",
    caption = caption
  ) +
  theme_minimal() +
  theme(

    # Main title
    plot.title = element_text(
      size = 20,
      face = "bold",
      color = "#222222",
      margin = margin(b = 5)
    ),

    # Subtitle
    plot.subtitle = element_text(
      size = 11,
      color = "#555555",
      lineheight = 1.1,
      margin = margin(b = 20)
    ),

    # Axis titles
    axis.title.x = element_text(
      size = 10,
      face = "bold",
      color = "#555555",
      margin = margin(t = 12)
    ),

    axis.title.y = element_text(
      size = 10,
      face = "bold",
      color = "#555555",
      margin = margin(r = 10)
    ),

    # Axis tick labels
    axis.text = element_text(
      size = 10,
      color = "#666666"
    ),

    # Caption
    plot.caption = element_text(
      size = 9,
      color = "#555555",
      hjust = 0,
      margin = margin(t = 15)
    ),

    # Legend
    legend.position = "right",
    legend.title = element_blank(),
    legend.text = element_text(
      size = 9,
      color = "#444444"
    ),

    # General spacing
    plot.margin = margin(
      t = 10,
      r = 15,
      b = 10,
      l = 10
    )
  )

base

Fonts

Let’s use: - Playfair Display — main title, matching OWID’s editorial serif style. - Lato — subtitle, axes, country labels, legend and caption.

Code
base <- base +
  theme_minimal(base_family = "Lato") +
  theme(
    plot.title = element_text(
      family = "Playfair Display",
      face = "bold",
      size = 22,
      color = "#222222"
    ),
    plot.subtitle = element_text(
      family = "Lato",
      size = 11
    ),
    axis.text = element_text(
      family = "Lato",
      size = 10
    ),
    axis.title = element_text(
      family = "Lato",
      size = 10
    ),
    legend.text = element_text(
      family = "Lato",
      size = 9
    ),
    plot.caption = element_text(
      family = "Lato",
      size = 9
    )
  )

base

Now that the fonts work, we just need to handle some final tweaks, especially regarding the cut off subtitles.

Code
base <- base +
  labs(
    title = title,
    subtitle = stringr::str_wrap(subtitle, width = 110),
    x = "GDP per capita",
    y = "Life satisfaction (0-10)",
    caption = caption
  ) +
  theme_minimal(base_family = "Lato") +
  theme(
    # Title
    plot.title = element_text(
      family = "Playfair Display",
      size = 20,
      face = "bold",
      color = "#333333",
      margin = margin(b = 8)
    ),

    # Subtitle
    plot.subtitle = element_text(
      family = "Lato",
      size = 10,
      color = "#555555",
      lineheight = 1.2,
      margin = margin(b = 15)
    ),

    # Axes
    axis.title = element_text(
      family = "Lato",
      size = 11,
      color = "#333333"
    ),

    axis.text = element_text(
      family = "Lato",
      size = 9,
      color = "#555555"
    ),

    # Legend
    legend.text = element_text(
      family = "Lato",
      size = 9
    ),

    # Caption
    plot.caption = element_text(
      family = "Lato",
      size = 8,
      color = "#777777",
      hjust = 0
    ),

    # General spacing
    plot.margin = margin(
      t = 15,
      r = 20,
      b = 10,
      l = 10
    )
  )

base

Code
ggsave(
  "gdp_happiness.png",
  plot = base,
  width = 12,
  height = 8,
  dpi = 300,
  bg = "white"
)