0

I would like to have a map with the Sahel. Namely 'Mali', 'Senegal', 'Guinea', 'Guinea-Bissau', 'Sierra Leone', 'Ivory Coast', 'Mali', 'Niger', 'Chad', 'Sudan', 'Eritrea', 'Ethiopia', 'Benin', 'Burkina Faso', 'Togo', 'Ghana', 'Nigeria', 'Cameroon', 'Gambia', 'Liberia', 'Mauritania' should be included.

The map should be really basic and the country names should be written within the boundaries.

Any idea how to code it with R?

5
  • Do you have a shapefile for Sahel? If not go here thematicmapping.org/downloads/TM_WORLD_BORDERS-0.3.zip
    – Ka_Papa
    May 22, 2018 at 9:13
  • I have a shape of the Sahel, but I need to find a map with more information, don't I? May 22, 2018 at 9:32
  • Creating maps with R can be challenging but If you want something without a north sign or a scale bar then it is pretty easy
    – Ka_Papa
    May 22, 2018 at 9:43
  • I just need to illustrate my case selection. So, a map with borders of the countries and maybe names in it would be enough. Any idea how the code should look like? May 22, 2018 at 9:45
  • Is this what you wanted?
    – Ka_Papa
    May 22, 2018 at 10:11

1 Answer 1

2

Just download the zip, unpack it and then run the following code

require("rgdal")
require("sp")
#read path to shapefile
shapefile_path=readline("Path to Shali shapefile: ")
#import shapefile
wrld_brdrs=readOGR(shapefile_path)
#select countries
slct=c('Senegal', 'Guinea', 'Guinea-Bissau', 
       'Sierra Leone', 'Mali', 'Niger', 
       'Chad', 'Sudan', 'Eritrea', 'Ethiopia', 'Benin', 'Burkina Faso', 
       'Togo', 'Ghana', 'Nigeria', 'Cameroon', 'Gambia', 'Liberia', 'Mauritania',"Cote d'Ivoire")

slct_areas=wrld_brdrs[wrld_brdrs$NAME==slct[1] | wrld_brdrs$NAME==slct[2] | wrld_brdrs$NAME==slct[3] |
         wrld_brdrs$NAME==slct[4] | wrld_brdrs$NAME==slct[5] | wrld_brdrs$NAME==slct[6] | 
         wrld_brdrs$NAME==slct[7] | wrld_brdrs$NAME==slct[8] | wrld_brdrs$NAME==slct[9] |
         wrld_brdrs$NAME==slct[10] | wrld_brdrs$NAME==slct[11] | wrld_brdrs$NAME==slct[12] | 
         wrld_brdrs$NAME==slct[13] | wrld_brdrs$NAME==slct[14] | wrld_brdrs$NAME==slct[15] |
         wrld_brdrs$NAME==slct[16] | wrld_brdrs$NAME==slct[17] | wrld_brdrs$NAME==slct[18] | 
         wrld_brdrs$NAME==slct[19] | wrld_brdrs$NAME==slct[20],]


#Like this
plot(wrld_brdrs, bg="light blue")
plot(slct_areas, col=rainbow(n=21),add=T)

#OR like this?
plot(slct_areas,col=rainbow(n=21), bg="light blue")
plot(wrld_brdrs,add=T)

#OR like this
plot(africa, bg="light blue")
plot(slct_areas, col=rainbow(n=21),add=T)


#plus labels on the map
plot(africa, bg="light blue")
map.text("world", regions = slct, add=T)
plot(slct_areas, col=rainbow(n=21),add=T)

Plot 1:

enter image description here

Plot 2: enter image description here

Plot 3:

enter image description here

5
  • Thanks this is what I have wanted. Two more question: Is there a possibility to fill in the country names & is there the possibility to check out how to write Mauritania & Ivory Coast, because they are not colored :) May 22, 2018 at 10:16
  • Ok, for Mauritania it was my bad because I selected 19 out of 20 and Mauritania was the 20th. As for Ivory Coast, I didn't know that it is also called Cote d' Ivoire, they don't teach that stuff in my Cartography classes. Anyway I fixed the code.
    – Ka_Papa
    May 22, 2018 at 10:38
  • @AmelioTornincasa I also added a line where you can plot your labels on the map
    – Ka_Papa
    May 22, 2018 at 11:43
  • Just click the tick next to my answer
    – Ka_Papa
    May 22, 2018 at 12:09
  • You could use slct_areas <- wrld_brdrs[wrld_brdrs$NAME %in% slct, ] instead of the long ... | ... | ... condition. Easier to write.
    – DJack
    May 23, 2018 at 20:44

Not the answer you're looking for? Browse other questions tagged or ask your own question.