The Languages of Africa

map
geography
spatial
Author

Ana Luisa Bodevan

Published

January 13, 2026

This week challenge dataset in on The Languages of Africa. Check the TidyTuesday GitHub repo for the data.

1. SETUP

Code
library(pacman)

pacman::p_load(
  tidytuesdayR,
  tidyverse,
  dplyr,
  janitor,
  ggtext,
  showtext,
  scales,
  glue,
  skimr,
  ggbranding,
  sf,
  rnaturalearth,
  cartogram)

tuesdata <- tidytuesdayR::tt_load('2026-01-13')

africa <- tuesdata$africa |>
  janitor :: clean_names()

rm(tuesdata)

2. DATA ANALYSIS

Code
### which countries speak the most languages?

africa %>%
  group_by(country) %>%
  summarise(n_languages = n_distinct(language)) %>%
  ggplot(aes(x = n_languages, y = country)) +
  geom_col()

3. DATA TIDYING

Code
### df with counts

africa_langs <- africa |>
  group_by(country) |>
  summarise(n_languages = n_distinct(language))

### africa boundaries

africa_map <- ne_countries(
  continent = "Africa",
  scale = "medium"
) |>
  select(name_en, geometry) |>
  mutate(
    name_en = case_when(
      name_en == "The Gambia" ~ "Gambia",
      name_en == "Democratic Republic of the Congo" ~ "Congo",
      TRUE ~ name_en
    )
  )

### join datasets

africa_data <- africa_map |>
  left_join(africa_langs, by = c("name_en" = "country"))

### check names mismatch

africa_data %>%
  filter(is.na(n_languages)) |>
  pull(name_en)
[1] "Somaliland"            "São Tomé and Príncipe" "Western Sahara"       
[4] "Guinea-Bissau"         "Republic of the Congo"
Code
### fix mismatching

africa_map <- ne_countries(
  continent = "Africa",
  scale = "medium"
) |>
  select(name_en, geometry) |>
  mutate(
    name_en = case_when(
      name_en == "The Gambia" ~ "Gambia",
      name_en == "Democratic Republic of the Congo" ~ "Congo",
      name_en == "Republic of the Congo" ~ "Congo-Brazzaville",
      name_en == "São Tomé and Príncipe" ~ "Sao Tome and Principe",
      name_en == "Guinea-Bissau" ~ "Guinea Bissau",
      TRUE ~ name_en
    )
  )

4. PLOT

Code
background_col <- "#f9f9f9" #"#FDFDFD",  #"#f5f5f2"
title_col <- "gray20"
subtitle_col <- "gray30"
text_col <- "gray30"

col <- viridisLite::plasma(100)

font_add_google("Bebas Neue", "bebas")
font_add_google("Roboto", "roboto")
# font_add_google("Font Name", "font_var")

showtext_auto()

title_font <- "bebas"
body_font <- "roboto"

title <- "LINGUISTIC DIVERSITY ACROSS AFRICA"
subtitle <- "Number of distinct languages spoken per country"

# brand <- branding(
  #github = "anabodevan",
  #bluesky = "1141bode.bsky.social",
  #text_size = "13pt",
  #icon_size = "13pt",
  #text_color = "gray40",
  #icon_color = "gray40",
  #line_spacing = 2L,
  #text_position = "after",
  #additional_text = "#TidyTuesday 2026 | Wikipedia: Languages of Africa",
  #additional_text_size = "10pt",
  #additional_text_color = "gray40",
  #text_family = body_font)
Code
ggplot(africa_data) +
  geom_sf(aes(fill = n_languages), color = "white", size = 0.3) +
  scale_fill_viridis_c(
    option = "plasma",
    name = "Number of\nLanguages",
    na.value = "grey90"
  ) +

  labs(
    title = title,
    subtitle = str_wrap(subtitle, 100)
  ) +

  theme_void() +
  theme(
    plot.background = element_rect(fill = background_col, color = NA),
    panel.background = element_rect(fill = background_col, color = NA),

    plot.title = element_text(
      family = title_font,
      size = 28,
      color = title_col,
      face = "bold",
      margin = margin(b = 10)
    ),
    plot.subtitle = element_text(
      family = body_font,
      size = 16,
      color = subtitle_col,
      margin = margin(b = 15)
    ),

    legend.title = element_text(
      family = body_font,
      color = text_col,
      size = 10
    ),
    legend.text = element_text(family = body_font, color = text_col, size = 9),
    legend.position = "right",

    axis.text = element_blank(),
    axis.ticks = element_blank(),

    panel.grid = element_blank(),
    plot.margin = margin(20, 20, 20, 20)) +

    add_branding(
        github = "anabodevan",
        bluesky = "1141bode.bsky.social",
        text_size = "11pt",
        icon_size = "11pt",
        text_color = "gray40",
        icon_color = "gray40",
        line_spacing = 1L,
        text_position = "after",
        additional_text = "#TidyTuesday 2026 | Wikipedia: Languages of Africa",
        additional_text_size = "10pt",
        additional_text_color = "gray40",
        text_family = body_font
        )