Load Packages

Prepare Data

## Loading the stat tables
lastyear <- max(unhcrdatapackage::end_year_population_totals_long$Year)

data <- dplyr::left_join( x= unhcrdatapackage::end_year_population_totals_long, 
                                                     y= unhcrdatapackage::reference, 
                                                     by = c("CountryAsylumCode" = "iso_3")) %>%
  filter(Population.type  == "REF" & Year == lastyear & !(is.na(UNHCRBureau))) %>%
  group_by(Year, CountryAsylumName, CountryAsylumCode, UNHCRBureau ) %>%
  summarise(Value2 = sum(Value) )
#> `summarise()` has grouped output by 'Year', 'CountryAsylumName', 'CountryAsylumCode'. You can override using the `.groups` argument.

# Population, GDP & GNP per Capita from WorldBank
wb_data <- wbstats::wb( indicator = c("SP.POP.TOTL", "NY.GDP.MKTP.CD", "NY.GDP.PCAP.CD", "NY.GNP.PCAP.CD"),
               startdate = 1951, enddate = 2020, return_wide = TRUE)
#> Warning: `wb()` was deprecated in wbstats 1.0.0.
#> Please use `wb_data()` instead.
# Renaming variables for further matching
names(wb_data)[1] <- "CountryAsylumCode"
names(wb_data)[2] <- "Year"


df2 <- merge(x = data, y = wb_data, by = c("CountryAsylumCode" ,"Year"), all.x = TRUE)
df2 <- df2[ !(is.na(df2$UNHCRBureau)) & !(is.na(df2$NY.GNP.PCAP.CD)) , ]
df2$prop <- df2$Value2 / df2$SP.POP.TOTL

Generate Plot

ggplot(df2, aes(y = Value2, x = NY.GDP.MKTP.CD)) + 
  geom_point(aes(col = UNHCRBureau)) + 
  #geom_smooth(method = "loess", se = F) +  
  scale_x_continuous( label = unhcRstyle::format_si(), ) + ## Format axis number
  scale_y_continuous( label = unhcRstyle::format_si(), 
                      limits = c(0, 1000000)) + ## Format axis number
  scale_color_viridis_d(direction = -1) +
  labs(title = "Refugee hosting is not correlated with Economic Wealth", 
       subtitle = "Refugee population Vs GDP", 
       y = "Refugee", 
       x = "Gross domestic product (GDP)", 
       caption = "2016 Figures, UNHCR https://www.unhcr.org/refugee-statistics/, World bank") +
  unhcRstyle::unhcr_theme() + ## Insert UNHCR Style
  theme(axis.title = element_text(size = 12))