Scale and north arrow for maps in R

A few months ago I produced some thematic maps of Bosnia (paper) using maptools and other packages in R, but I didn’t include scales or a north arrow. It sounds simple and sp has functions for doing those things, but I couldn’t get it to work well with my maps. Here is a basic map of Bosnia’s pre-war municipalities:



The function map.scale() from the maps package adds a scale. The position is in map units, latitude/longitude in this case:

map.scale(x=15.5, y=42.75, ratio=FALSE, relwidth=0.2)

And GISTools north.arrow for the north arrow. Units are also in map units. This package has a map scale function as well, which looks nicer but is a little bit more complicated to set up.

north.arrow(xb=15.75, yb=43.25, len=0.05, lab="N")

This will produce the following map:

Adding these to a function I wrote for producing thematic maps of Bosnia produces this pretty nice map (with scale and north arrow!) of document per capita civil war deaths:

Here is the function (which is pretty specific to the data I use):

ThematicMap<-function(vector, breaks, title, legend) {

  plotvar <- unlist(vector)
  nclr <- 9
  plotclr <- brewer.pal(nclr, "Reds")
  fillRed <- colorRampPalette(plotclr)
  plotvar[plotvar >= maxy] <- maxy -1
  colcode <- fillRed(maxy)[round(plotvar) + 1]
  plot(bosnia, col = colcode, lty = 0, border = "gray")
  plot(, add=TRUE, lwd=1, border = "gray30")
  plot(bosnia.front93, add = TRUE, lty="solid", lwd=1.5, col="darkblue")
  map.scale(x=15.5, y=42.75, relwidth=0.2, ratio=FALSE)
  north.arrow(xb=15.75, yb=43.25, len=0.05, lab="N")
  title(main = title)
  colorlegend(posy = c(0.05,0.9), posx = c(0.9,0.92),
              col = fillRed(maxy),
              zlim=c(0, maxy), zval = breaks,
              main = legend,
              main.cex = 0.9)
} <- (killed/pop91*1000)
maxy <- 50
breaks <- c(0, 10, 20, 30, 40, Inf)
print(ThematicMap(,breaks,"Documented killings during the Bosnian War","per 1,000"))

11 Comments on “Scale and north arrow for maps in R”

  1. Roland says:

    Dear Alex,
    congratulations to your blog and work. Very interesting and inspring. I am rather new to R and maps – do you have an idea where to get a map with today’s municipal/canton boundaries of Bosnia? Many thanks & congrats again. ro

  2. Schweizer says:

    Hello Andreas,
    just a quick question. I am not able to install the package GISTools, is it only working for versions 0.7-1 and not versions 2?
    Thank you for your help

    • Hi Jacqueline,
      I just tried reinstalling GISTools on R 2.15.3 and it worked without problems. But for install problems, have you tried contacting the package author/maintainer listed on CRAN?

  3. Tim Greening-Jackson says:


    Thanks for such a superb tutorial. I am extremely new to R and maps and found it very helpful. The only thing was my map.scale() command didn’t work properly but as ever I’m sure I’ll get it working soon.

  4. Bruno says:

    Very nice! Thanks a lot for this useful post! Just a tip, as the GISTools also has the function map.scale(), we can force this function for the maps library by using maps::map.scale(x=…).

  5. Lorenzo says:

    thank you, very useful. thank you very much

  6. Benjamin says:

    Hi there, just had a quick question: I’ve managed to input a north arrow and legend onto my map, but is there an easy way to remove them if I am not happy with the positioning? (I’m quite new to R as well)

    • Hi, you’ll have to redo the map, i.e. start again from plot(...) and just leave out the map.scale and north.arrow parts. Or if you are using the function I posted, comment out those commands and source the function again.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

Join 346 other followers