Full Analysis Report

Basic EDA

# Imports
library(refugees) # UNHCR's refugees R package
library(tidyverse)
library(patchwork) # To combine plots
library(grid) # For unit() function to set margin dimensions
library(ggtext) # For Markdown/HTML formatting in text elements

# Load Data
population <- readr::read_csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/main/data/2023/2023-08-22/population.csv") %>%
  mutate(`refugees (M)` = refugees / 1e6) # convert to millions


# Filter regions
selected_regions <- population %>%
  filter(coo_iso %in% c("SYR", "AFG", "MMR", "YEM", "SDN", "COD"))

# Check Data types
glimpse(selected_regions)
Rows: 6,401
Columns: 17
$ year              <dbl> 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010…
$ coo_name          <chr> "Afghanistan", "Dem. Rep. of the Congo", "Sudan", "D…
$ coo               <chr> "AFG", "COD", "SUD", "COD", "SUD", "COD", "SUD", "SY…
$ coo_iso           <chr> "AFG", "COD", "SDN", "COD", "SDN", "COD", "SDN", "SY…
$ coa_name          <chr> "Afghanistan", "Algeria", "Algeria", "Angola", "Ango…
$ coa               <chr> "AFG", "ALG", "ALG", "ANG", "ANG", "ARE", "ARE", "AR…
$ coa_iso           <chr> "AFG", "DZA", "DZA", "AGO", "AGO", "EGY", "EGY", "EG…
$ refugees          <dbl> 0, 66, 0, 13648, 159, 24, 10035, 8, 205, 6, 5, 5518,…
$ asylum_seekers    <dbl> 0, 26, 20, 1508, 212, 14, 12476, 0, 9, 0, 0, 68, 5, …
$ returned_refugees <dbl> 0, 0, 0, 0, 0, 0, 251, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
$ idps              <dbl> 351907, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
$ returned_idps     <dbl> 3366, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
$ stateless         <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
$ ooc               <dbl> 838250, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
$ oip               <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …
$ hst               <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …
$ `refugees (M)`    <dbl> 0.000000, 0.000066, 0.000000, 0.013648, 0.000159, 0.…
selected_regions$coo_name <- as.factor(selected_regions$coo_name) # Convert to factor

conflict_regions <- selected_regions %>%
  mutate(year = as.numeric(year)) %>% # Ensure year is numeric
  group_by(year, coo_name) %>% # Group by year and country of origin
  summarize(total_refugees = sum(`refugees (M)`))

Custom Theme

All visualizations in this analysis follow a custom theme to maintain a consistent style across all plots.

The theme is set globally via .Rprofile.

# Custom Color Palette
region_colors <- c(
  "Syrian Arab Rep." = "tomato2",
  "Afghanistan" = "palevioletred1",
  "Myanmar" = "turquoise1",
  "Sudan" = "orange",
  "Dem. Rep. of the Congo" = "saddlebrown",
  "Yemen" = "olivedrab2"
)

Combined plots (Facet vs Individual Scaling)