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?

closed as off-topic by PolyGeo May 22 '18 at 11:54

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions seeking help to debug/write/improve code must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Providing a clear problem statement and evidence of a code attempt will help others to help you. See: How to create a Minimal, Complete, and Verifiable example." – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Do you have a shapefile for Sahel? If not go here thematicmapping.org/downloads/TM_WORLD_BORDERS-0.3.zip – George Nostradamos May 22 '18 at 9:13
  • I have a shape of the Sahel, but I need to find a map with more information, don't I? – Amelio Tornincasa May 22 '18 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 – George Nostradamos May 22 '18 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? – Amelio Tornincasa May 22 '18 at 9:45
  • Is this what you wanted? – George Nostradamos May 22 '18 at 10:11

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

#read path to shapefile
shapefile_path=readline("Path to Shali shapefile: ")
#import shapefile
#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")

#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

  • 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 :) – Amelio Tornincasa May 22 '18 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. – George Nostradamos May 22 '18 at 10:38
  • @AmelioTornincasa I also added a line where you can plot your labels on the map – George Nostradamos May 22 '18 at 11:43
  • Just click the tick next to my answer – George Nostradamos May 22 '18 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 '18 at 20:44

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