Problem with creating breaks and setting colours for choropleth maps in RStudio

41 views Asked by At

I am trying to plot a choropleth map of Ethiopia that shows the number of internally displaced persons (IDPs) as a percentage of the total population for each Zone (county). I have uploaded the Ethiopia Shapefile to R (Ethiopia_geoboundaries_ADM2), as well as the %IDP data for Ethiopia (Ethiopia_Rmap) and merged them. However, when I use spplot, the colour range only fits the current data range. I have other countries which I want to compare these results to, so would like a uniform set of colour breaks for each map.

The colour breaks I would like are: <5%, 5-10%, 10-25%, 25-50%, 50-75%, 75%+

Current code and output:

> setwd("~/Documents/Acumen_Data/IDMC_Map_Data/Ethiopia")
> library(spdep)
> library(rgdal)
> library(sf)
> library(terra)
> Ethiopia_Rmap <- read_excel("Ethiopia_Rmap.xlsx")
> Ethiopia_geoBoundaries_ADM2 <- readOGR(dsn = ".", layer = "eth_admbnda_adm2_csa_bofedb_2021")
> Ethiopia_Static_Map = merge(Ethiopia_geoBoundaries_ADM2,Ethiopia_Rmap,by.x="ADM2_EN",by.y="Zone")
> ColourPalette = brewer.pal(n=7, name="PuBu")
> spplot(Ethiopia_Static_Map,"IDP_Perc", col.regions=ColourPalette)

This is the output map currently

This is the Ethiopia_Rmap population percentage data

This is the Ethiopia shapefile

I want a map that has a legend somewhat like this, rather than from 0-50. I think this means somehow defining set breaks of class intervals? Please help! thank you!

Sample legend - doesnt have to be these exact colours!

Ethiopia_geoboundaries_ADM2 data is from this link - https://data.humdata.org/dataset/cb58fa1f-687d-4cac-81a7-655ab1efb2d0/resource/63c4a9af-53a7-455b-a4d2-adcc22b48d28/download/eth_adm_csa_bofedb_2021_shp.zip

Ethiopia_Rmap data example using dput

Ethiopia_Rmap_Structure = dput(Ethiopia_Rmap[1:30,])

Ethiopia_Rmap = structure( list( Region = c( "Afar", "Afar", "Afar", "Afar", "Afar", "Amhara", "Amhara", "Amhara", "Amhara", "Amhara", "Amhara", "Amhara", "Amhara", "Amhara", "Amhara", "Amhara", "Benishangul-Gumuz Region", "Benishangul-Gumuz Region", "Gambela", "Gambela", "Harari", "Oromia", "Oromia", "Oromia", "Oromia", "Oromia", "Oromia", "Oromia", "Oromia", "Oromia" ), Zone = c( "Aswi /Zone 1", "Fanti /Zone 4", "Gabi /Zone 3", "Hari /Zone 5", "Kilbati /Zone 2", "Argoba (special Woreda)", "Awi", "East Gojam", "North Gondar", "North Shewa (AM)", "North Wello", "Oromia", "South Gondar", "South Wello", "Wag Hamra", "West Gojam", "Assosa", "Metekel", "Agnewak", "Nuwer", "Harari", "Arsi", "Bale", "Borena", "East Hararge", "East Wellega", "Guji", "Horo Gudru Wallega", "Jimma", "Kelem Wallega" ), IDP_Population = c( 22668, 1531, 28011, 2580, 41786, 4498, 28622, 20633, 25407, 66296, 30243, 7370, 28704, 24292, 38934, 143028, 28603, 94798, 5296, 39208, 3037, 4064, 10650, 220540, 143853, 140374, 100972, 42496, 14893, 26351 ), Total_Population = c( 641584, 333296, 328636, 254909, 489698, 42250, 1328104, 2845753, 4066517, 2464232, 1989563, 611456, 2701503, 3387395, 548884, 2755600, 492344, 441297, 204358, 172105, 283000, 3980967, 2119829, 1431922, 4035797, 1847649, 2073775, 859339, 3638103, 1191582 ), IDP_Perc = c( 3.53, 0.46, 8.52, 1.01, 8.53, 10.65, 2.16, 0.73, 0.62, 2.69, 1.52, 1.21, 1.06, 0.72, 7.09, 5.19, 5.81, 21.48, 2.59, 22.78, 1.07, 0.1, 0.5, 15.4, 3.56, 7.6, 4.87, 4.95, 0.41, 2.21 ) ), row.names = c(NA,-30L), class = c("tbl_df", "tbl", "data.frame") )

0

There are 0 answers