# Alternative North Arrow using R GIStools package?

I'm really digging the `R` package `GISTools` for making some basic maps. The default north arrow, created with `north.arrow` looks ok, but I'm wondering if it would be possible to use a different north arrow. It seems like no other arrow is available in the package, so how could I create my own north arrow? The documentation for the package states

Draws a north arrow on a map. The arrow itself is drawn using polygon and any extra parameters are passed to this call.

So I would need to create the arrow as a polygon? How could I implement this? And would it be possible to modify the source code of `north.arrow` to offer several different arrows?

I found this paper from the Journal of Statistical Software (https://www.jstatsoft.org/article/view/v019c01/v19c01.pdf)

It provides the following function:

``````    northarrow <- function(loc,size,bearing=0,cols,cex=1,...) {
# checking arguments
if(missing(loc)) stop("loc is missing")
if(missing(size)) stop("size is missing")
# default colors are white and black
if(missing(cols)) cols <- rep(c("white","black"),8)
# calculating coordinates of polygons
# drawing polygons
for (i in 1:15) {
x1 <- c(x[i],x[i+1],loc)
y1 <- c(y[i],y[i+1],loc)
polygon(x1,y1,col=cols[i])
}
# drawing the last polygon
polygon(c(x,x,loc),c(y,y,loc),col=cols)
# drawing letters
b <- c("E","N","W","S")
for (i in 0:3) text((size+par("cxy"))*cos(bearing+i*pi/2)+loc,
(size+par("cxy"))*sin(bearing+i*pi/2)+loc,b[i+1],
cex=cex)
}
``````

I got it to work doing this:``` library(GISTools) data(newhaven) plot(blocks) xy = c(530000,160000)#use locator() to get the x,y values for arrow placement northarrow(loc = xy, size = 10000)#finding the correct size value is a guessing game```

You can fiddle with the polygon commands, but this one looks pretty nice. --Also there is another arrow available in the prettymapr package. Cheers, Lewis

• Fantastic! Great first answer btw. I didn't test it but it looks solid and since you got it to work I'm marking it as correct.
– haff
Jun 30, 2017 at 4:06