Get the data

Load the required packages

library(tidyverse)
library(sf)
if (!require(rhdx))
  remotes::install_gitlab("dickoa/rhdx")
library(rhdx)
rhdx:::rhdx_cache$mkdir()
if (!require(rgeoboundaries))
  remotes::install_gitlab("dickoa/rgeoboundaries")
library(rgeoboundaries)
library(janitor)
library(tmap)

Look at the data

Using the rhdx package we can pull the dataset and access the file (resource), the latest round of the assessment baseline is usually the first HDX resource on IOM baseline dataset

set_rhdx_config()
mli_idps <- pull_dataset("mali-baseline-assessment-data-iom-dtm") %>%
  get_resource(1) %>%
  read_resource() %>%
  clean_names()
## Reading sheet:  Mali_Baseline_R62
glimpse(mli_idps)
## Rows: 49
## Columns: 25
## $ snapshot_date                 <dbl> 43889, 43889, 43889, 43889, 43889, 4388…
## $ admin_0                       <chr> "Mali", "Mali", "Mali", "Mali", "Mali",…
## $ admin_0_pcode                 <chr> "MLI", "MLI", "MLI", "MLI", "MLI", "MLI…
## $ admin_1                       <chr> "Kayes", "Kayes", "Kayes", "Kayes", "Ka…
## $ admin_1_pcode                 <chr> "MLI01", "MLI01", "MLI01", "MLI01", "ML…
## $ admin_2                       <chr> "Kayes", "Bafoulabé", "Diema", "Kita", …
## $ admin_2_pcode                 <chr> "MLI001001", "MLI001002", "MLI001003", …
## $ admin_3                       <chr> "Kayes Commune", "Oualia Commune", "Tro…
## $ admin_3_pcode                 <chr> "MLI00100112", "MLI00100211", "MLI00100…
## $ total_no_of_id_ps_hh          <dbl> 8, 4, 20, 337, 2, 10, 17, 108, 298, 31,…
## $ total_no_of_id_ps_ind         <dbl> 45, 21, 159, 1326, 12, 61, 89, 536, 140…
## $ main_displacement_start_date  <dbl> 40969, 40969, 40969, 40969, 40969, 4096…
## $ total_no_of_returnees_hh      <dbl> 0, 0, 0, 37, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ total_no_of_returnees_ind     <dbl> 0, 0, 0, 219, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ total_no_migrant_households   <lgl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,…
## $ total_no_migrant_individuals  <lgl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,…
## $ country_of_origin_of_idp      <chr> "Mali", "Mali", "Mali", "Mali", "Mali",…
## $ admin_1_area_of_origin_of_idp <chr> "KaYes", "KaYes", "KaYes", "KaYes", "Ka…
## $ confidentiality               <chr> "No", "No", "No", "No", "No", "No", "No…
## $ type_of_displacement          <chr> "Conflict", "Conflict", "Conflict", "Co…
## $ conflict                      <chr> "Yes", "Yes", "Yes", "Yes", "Yes", "Yes…
## $ insecurity                    <chr> "Yes", "Yes", "Yes", "Yes", "Yes", "Yes…
## $ natural_disaster              <chr> "No", "No", "No", "No", "No", "No", "No…
## $ political_reasons             <chr> "No", "No", "No", "No", "No", "No", "No…
## $ eco_nomic_reasons             <chr> "No", "No", "No", "No", "No", "No", "No…

We can check the data by doing a bar chart

mli_idps_tot_adm1 <- mli_idps %>%
  group_by(admin_1) %>%
  summarise(n_idps = sum(total_no_of_id_ps_ind, na.rm = TRUE)) %>%
  ungroup()

mli_idps_tot_adm1 %>%
  ggplot(aes(reorder(admin_1, n_idps), n_idps)) +
  geom_col() +
  labs(x = "", y = "") +
  coord_flip()

Get the region boundaries data of Mali

mli_adm1 <- gb_adm1("mali")
mli_adm1 %>%
  tm_shape() +
  tm_borders()

Let’s join the the data

mli_idps_tot_adm1 <- left_join(mli_idps_tot_adm1,
                               mli_adm1,
                               by = c("admin_1" = "shapeName")) %>%
  st_as_sf(sf_column_name = "geometry")


mli_idps_tot_adm1 %>%
  tm_shape() +
  tm_polygons(col = "n_idps")