vignettes/Biggest_decrease_in_Refugee_Population.Rmd
Biggest_decrease_in_Refugee_Population.Rmd
## Loading the stat tables
lastyear <- max(unhcrdatapackage::end_year_population_totals_long$Year)
tenyears <- lastyear -10
data <- dplyr::left_join( x= unhcrdatapackage::end_year_population_totals_long,
y= unhcrdatapackage::reference,
by = c("CountryAsylumCode" = "iso_3")) %>%
filter(Population.type == "REF") %>%
filter(Year == tenyears | Year == lastyear) %>%
group_by( CountryAsylumName, Year) %>%
summarise(Value2 = sum(Value) ) %>%
select(CountryAsylumName, Year, Value2) %>%
mutate(CountryAsylumName = str_replace(CountryAsylumName, " \\(Bolivarian Republic of\\)", ""),
CountryAsylumName = str_replace(CountryAsylumName, "Iran \\(Islamic Republic of\\)", "Iran"),
CountryAsylumName = str_replace(CountryAsylumName, "United Kingdom of Great Britain and Northern Ireland", "UK")) %>%
mutate(Year = paste0("year_",Year )) %>%
spread(Year, Value2) %>%
mutate(gap = year_2011 - year_2021) %>%
arrange(desc(gap)) %>%
head(10) %>%
gather(key = Year,
value = Value2,
-CountryAsylumName,
-gap)
#> `summarise()` has grouped output by 'CountryAsylumName'. You can override using the `.groups` argument.
#Make plot
ggplot(data,
aes(x = reorder(CountryAsylumName, gap),
y = Value2,
fill = as.factor(Year))) +
coord_flip() +
geom_bar(stat = "identity", position = "dodge") +
geom_hline(yintercept = 0, size = 1, colour = "#333333") +
scale_fill_manual(values = c("#0072bc", "#FAAB18")) +
labs(title = "Biggest Decrease of Population",
subtitle = paste0("10 Biggest change in Refugee Population, ", tenyears," - ",lastyear),
x="", y ="",
caption = "UNHCR https://www.unhcr.org/refugee-statistics/") +
scale_y_continuous( label = scales::label_number_si()) + ## Format axis number
unhcRstyle::unhcr_theme() + ## Insert UNHCR Style
theme(panel.grid.major.x = element_line(color = "#cbcbcb"),
panel.grid.major.y = element_blank()) ### changing grid line that should appear