## Getting world map for mapping
world <- rnaturalearth::ne_countries(scale = "small", returnclass = "sf")
centroids <- sf::st_transform(world$geometry, '+init=epsg:3857') %>%
## Reprojected in order to get centroid
sf::st_centroid() %>%
# this is the crs from d, which has no EPSG code:
sf::st_transform(., '+init=epsg:4326') %>%
# since we want the centroids in long lat:
sf::st_geometry()
#> Warning in CPL_crs_from_input(x): GDAL Message 1: +init=epsg:XXXX syntax is
#> deprecated. It might return a CRS with a non-EPSG compliant axis order.
world_points <- cbind(world, sf::st_coordinates(centroids))
## 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.
# Merge data with geographic coordinates
world <- merge(x = world , y = data, by.y = "CountryAsylumCode" , by.x = "iso_a3")
df3 <- merge(x = data , y = world_points, by.x = "CountryAsylumCode" , by.y = "iso_a3")