thisbureau <- "Americas"
lastyear <- max(unhcrdatapackage::end_year_population_totals_long$Year)
## https://jokergoo.github.io/circlize_book/book/
chords <- unhcrdatapackage::end_year_population_totals %>%
dplyr::left_join( unhcrdatapackage::reference %>%
select(coa_region = `UNHCRBureau`, iso_3), by = c("CountryAsylumCode" = "iso_3")) %>%
filter(coa_region == thisbureau & Year == lastyear) %>%
dplyr::mutate(across(REF:VDA, ~replace_na(as.numeric(.), 0)),
total = REF + ASY + VDA, #+ IDP + STA + OOC,
# Lump together factor levels into "other"
CountryAsylumName = forcats::fct_lump_prop(CountryAsylumName, prop = .02, w = total),
CountryOriginName = forcats::fct_lump_prop(CountryOriginName, prop = .02, w = total)) %>%
group_by(CountryOriginName, CountryAsylumName) %>%
summarize(total = sum(total), .groups = "drop") %>%
# CountryOriginName = fct_recode(CountryOriginName, "Other" = "China")
mutate(CountryOriginName = str_replace(CountryOriginName, " \\(Bolivarian Republic of\\)", ""),
CountryAsylumName = str_replace(CountryAsylumName, " \\(Bolivarian Republic of\\)", ""),
CountryOriginName = str_replace(CountryOriginName, " \\(Plurinational State of\\)", ""),
CountryAsylumName = str_replace(CountryAsylumName, " \\(Plurinational State of\\)", ""),
CountryOriginName = str_replace(CountryOriginName, "United States of America", "USA"),
CountryAsylumName = str_replace(CountryAsylumName, "United States of America", "USA"))