I created a Sankey diagram showing the flow of refugees by continent of origin from 2010 to 2022. The diagram is composed of vertical lines representing each year between 2010 and 2022. The continents Africa, Asia, Europe, North America, Oceania, and South America are represented by colored segments. Seven Seas (open ocean) was removed from dataset. The thickness of the lines between years represents the flow of refugees. The chart provides insights into the changing patterns of refugee movement over the years.

Loading packages, data, fonts and difining colors

# Loading packages
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.2     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ ggplot2   3.4.2     ✔ tibble    3.2.1
## ✔ lubridate 1.9.2     ✔ tidyr     1.3.0
## ✔ purrr     1.0.1     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(tidytuesdayR)
library(showtext)
## Lade nötiges Paket: sysfonts
## Lade nötiges Paket: showtextdb
library(glue)
library(ggtext)
library(rnaturalearth)
## The legacy packages maptools, rgdal, and rgeos, underpinning the sp package,
## which was just loaded, will retire in October 2023.
## Please refer to R-spatial evolution reports for details, especially
## https://r-spatial.org/r/2023/05/15/evolution4.html.
## It may be desirable to make the sf package available;
## package maintainers should consider adding sf to Suggests:.
## The sp package is now running under evolution status 2
##      (status 2 uses the sf package in place of rgdal)
## Support for Spatial objects (`sp`) will be deprecated in {rnaturalearth} and will be removed in a future release of the package. Please use `sf` objects with {rnaturalearth}. For example: `ne_download(returnclass = 'sf')`
library(ggsankey)

#Loading Data
tuesdata <- tidytuesdayR::tt_load(2023, week = 34)
## --- Compiling #TidyTuesday Information for 2023-08-22 ----
## --- There is 1 file available ---
## --- Starting Download ---
## --- Download complete ---
population <- tuesdata$population

world <- ne_countries(scale = "medium", returnclass = "sf")



# vertical lines
line_data = tibble(x = seq(2010, 2022, 2),
                   xend = seq(2010, 2022, 2),
                   y = 15000000,
                   yend = -15000000)

# Loading fonts and colors
font_add('fa-reg', 'c:/Users/info/OneDrive/Dokumente/fonts/Font Awesome 6 Free-Regular-400.otf')
font_add('fa-brands', 'c:/Users/info/OneDrive/Dokumente/fonts/Font Awesome 6 Brands-Regular-400.otf')
font_add('fa-solid', 'c:/Users/info/OneDrive/Dokumente/fonts/Font Awesome 6 Free-Solid-900.otf')
showtext_auto()
bg <- "lightgrey"
col1 <- thematic::okabe_ito()[1]
col2 <- thematic::okabe_ito()[2]
col3 <- thematic::okabe_ito()[3]
col4 <- thematic::okabe_ito()[4]
col5 <- thematic::okabe_ito()[5]
col6 <- thematic::okabe_ito()[6]
col7 <- thematic::okabe_ito()[7]
col8 <- thematic::okabe_ito()[8]
col_choices = c(col1,col2,col3,col4,col5,col6)

Text generation

# text creation
twitter <- glue("<span style='color:{col1};font-family:fa-brands;'>&#xf099;</span>")
mastodon <- glue("<span style='color:{col1};font-family:fa-brands;'>&#xf4f6;</span>")
link <- glue("<span style='color:{col1};font-family:fa-solid;'>&#xf0c1;</span>")
data <- glue("<span style='color:{col1};font-family:fa-solid;'>&#xf1c0;</span>")
hash <- glue("<span style='color:{col1};font-family:fa-solid;'>&#x23;</span>")
space <- glue("<span style='color:{bg}'>-</span>")
space2 <- glue("<span style='color:{bg}'>--</span>") # can't believe I'm doing this

africa <- glue("<span style='color:{col1}'><b>Africa</b></span>")
asia <- glue("<span style='color:{col2}'><b>Asia</b></span>")
europe <- glue("<span style='color:{col3}'><b>Europe</b></span>")
n.america <- glue("<span style='color:{col4}'><b>North America</b></span>")
oceania <- glue("<span style='color:{col5}'><b>Oceania</b></span>")
s.america <- glue("<span style='color:{col6}'><b>South America</b></span>")

t <- "<b>Refugees by continent of orgin</b>"
s <- glue("Tidy Tuesday 2023 | Week 34 <br> Continents: {africa}, {asia}, {europe}, {n.america}, {oceania} and {s.america}")
cap <- glue("{twitter}{space2}@web_design_fh{space2} 
	{space2}{mastodon}{space2}@frankhaenel @fosstodon.org{space2}
	{space2}{link}{space}{space2}www.frankhaenel.de<br>
	{data}{space2} refugees-package{space2}
	{space2}{hash}{space2}tidytuesday")

Plot

population %>%
left_join(world %>% select(iso_a3, continent),
by = c("coo_iso" = "iso_a3")) %>%
group_by(year,continent) %>% summarise(sum_ref = sum(refugees)) %>%
drop_na() %>%
filter(continent != "Seven seas (open ocean)") %>%
ggplot(mapping = aes(x = year,
value = sum_ref,
node = factor(continent),
next_node = factor(continent),
fill = factor(continent))) +
geom_segment(data = line_data,
mapping = aes(x = x,
xend = xend,
y = y,
yend = yend,
group = x),
colour = "#2F4F4F",
linetype = "dashed",
linewidth = 0.3,
inherit.aes = FALSE) +
geom_sankey_bump(space = 100,
color = "transparent",
smooth = 6,
alpha = 0.8,show.legend = F) +
scale_fill_manual(values = col_choices) +
scale_x_continuous(breaks = seq(2010, 2022, 2),
expand = expansion(add = c(0.05, 0.5))) +
scale_y_continuous(expand = expansion(add = c(0, 0)),
limits = c(-15000000, 15000000)) +
theme_void() +
labs(title = t, subtitle = s, caption = cap) +
theme(plot.margin = margin(10, 10, 10, 20),
panel.background = element_rect(fill=bg, colour = bg),
plot.background = element_rect(fill=bg),
plot.title = element_markdown(size = 20, hjust = 0, lineheight = 1.3),
plot.subtitle = element_markdown(size = 18, hjust = 0, lineheight = 1.3),
plot.caption = element_markdown(size = 12, hjust = 0, lineheight = 1.3),
axis.text.x = element_text(size = 14))
## `summarise()` has grouped output by 'year'. You can override using the
## `.groups` argument.
Sankey diagram showing the flow of refugees by continent of origin from 2010 to 2022. The diagram is composed of vertical lines representing each year between 2010 and 2022. The continents Africa, Asia, Europe, North America, Oceania, and South America are represented by colored segments. The thickness of the lines between years represents the flow of refugees. The chart provides insights into the changing patterns of refugee movement over the years.