Tree Plot of African Lnaguages
1. R code
Show code # | echo: true
# | eval: false
# | warning: false
# | message: false
if ( ! require ( tidyverse ) ) { install.packages ( "tidyverse" ) ; library ( tidyverse ) }
if ( ! require ( scales ) ) { install.packages ( "scales" ) ; library ( scales ) }
if ( ! require ( treemapify ) ) { install.packages ( "treemapify" ) ; library ( treemapify ) }
if ( ! require ( CustomGGPlot2Theme ) ) { devtools :: install ( "CustomGGPlot2Theme" ) ; library ( CustomGGPlot2Theme ) }
options ( scipen= 999 )
africa <- readr :: read_csv ( 'https://raw.githubusercontent.com/rfordatascience/tidytuesday/main/data/2026/2026-01-13/africa.csv' )
africa_tree <- africa %>%
group_by ( family , language ) %>%
summarise (
native_speakers = max ( native_speakers , na.rm = TRUE ) ,
.groups = "drop"
) %>%
filter ( native_speakers >= 500000 ) %>%
group_by ( family ) %>%
mutate (
language_label = paste0 (
language ,
"\n" ,
scales :: label_number ( accuracy = 0.1 , scale_cut = cut_short_scale ( ) ) ( native_speakers )
)
)
plot1 <- ggplot (
africa_tree ,
aes (
area = native_speakers ,
fill = family ,
label = language_label ,
subgroup = family
)
) +
geom_treemap ( ) +
geom_treemap_subgroup_border ( ) +
geom_treemap_subgroup_text (
place = "centre" ,
grow = TRUE ,
alpha = 0.7 ,
min.size = 0
) +
geom_treemap_text (
colour = "white" ,
place = "centre" ,
reflow = TRUE ,
size = 8
) +
labs (
title = "African Languages by Family" ,
subtitle = "Showing langauge families with at least 500k speakers" ,
fill = "Language Family"
) +
theme ( legend.position = "bottom" )
Back to top