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)
library(tidytuesdayR) library(showtext)
library(glue) library(ggtext) library(rnaturalearth)
library(ggsankey) #Loading Data tuesdata <- tidytuesdayR::tt_load(2023, week = 34)
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;'></span>") mastodon <- glue("<span style='color:{col1};font-family:fa-brands;'></span>") link <- glue("<span style='color:{col1};font-family:fa-solid;'></span>") data <- glue("<span style='color:{col1};font-family:fa-solid;'></span>") hash <- glue("<span style='color:{col1};font-family:fa-solid;'>#</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))