I would like to ask if some could help me draw the maps of a portion of West Africa i.e. Guinea, Liberia and Sierra Leone using LaTeX? Thank you.

Here is the code and results for using R and LaTex with the R package knitr http://yihui.name/knitr/ . The maps are plotted from a polynomial database in mapdata. A pdf image is created which then is typeset using LaTeX. (lots of details omitted)

A couple of notes

  1. This was done on Win 8.1 with Miktex (full installation) and R 3.1.2 with the maps and mapdata packages installed.

  2. This is not the only way to plot maps using R. There are links for using googlemaps, geodata, etc. Simply search the web with "using R" maps country and browse.

  3. If you go to http://www.r-bloggers.com/?s=maps you will have links to over 800 discussions and examples of using maps in R.

\documentclass[10pt,letterpaper]{article}
\begin{document}
Map of Guinea, Liberia, and Sierra Leone

<<>>=
### Reference: 
###  https://www.students.ncl.ac.uk
###      /keith.newman/r/maps-in-r
###  http://stackoverflow.com/questions/22282713
###      /r-maps-package-how-to-draw-lines-between-cities-within-the-country

library(maps)
library(mapdata)
map('worldHires',c('Guinea','Liberia','Sierra Leone'))
points(-13.67847,9.537029,col=2,pch=18)
text(-13.67847,9.537029, "Conakry", pos = 1)
### points(longitude, latitude, color, symbol shape)
@
\end{document}

Map from above code

  • Can you add a few explanations? Is this is stored (multipart) figure, or are the outlines stored in a library and actually typeset? – Johannes_B Feb 25 '15 at 20:12
  • Looks a bit more detailed, but doesn't have the flair of chat.stackexchange.com/transcript/message/20250016#20250016 ;-) – Johannes_B Feb 25 '15 at 20:12
  • Thanks in advance. I would like to add some names to it like Conakry being the capital of Guinea and other names. Could you do that too? – user28251 Feb 25 '15 at 20:24
  • When I did my edit, I was unable to properly delimit the code as code. It appears that the use of imbedded R syntax confuses the system. – R. Schumacher Feb 25 '15 at 22:22

You can consider using the getmap package. An example:

\documentclass{article}
\usepackage{getmap}
\usepackage{graphicx}

\begin{document}
\getmap [file=africa, mode=gm, type=terrain,xsize=500, ysize=500, scale=2, zoom=6]{Sierra Leone}
\includegraphics[width=9cm]{africa}
\end{document}

enter image description here

  • Sorry for the bad formating. I'm posting from hospital via smart phone - no editor :-( Maybe, someone can edit the answer! – Josef Feb 26 '15 at 13:57
  • I added an example. – Torbjørn T. Feb 26 '15 at 16:19
  • Wonderful work guys – user28251 Feb 27 '15 at 15:30

I'm away from my computer at the moment so this will be a sparse answer, but a more visual answer is to use QGIS and then export the map as a PDF and include it using \includegraphics{}

You can get qgis here: http://www.qgis.org/

From there just Google "shape file " open it in QGIS, set the coloring however you want, and use the print preparation dialogue to save the section you want to.

The advantage of qgis is that it's easier to include many layers of map data and then only export sections.

I used this with road, waterways, and outline data across three countries.

  • I really appreciate your answer. Thank you. – user28251 Feb 25 '15 at 23:46
  • @user28251 I appreciate what the other person is doing with R, I just wanted to provide a more approachable, GUI option! I recently did a project where I scanned old maps out of books and then georeferenced them in QGIS and then wrote my report in LaTeX, so it's a recent question for me. – Ryan Feb 25 '15 at 23:56

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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