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
radii <- rep(size/c(1,4,2,4),4)
x <- radii[(0:15)+1]*cos((0:15)*pi/8+bearing)+loc[1]
y <- radii[(0:15)+1]*sin((0:15)*pi/8+bearing)+loc[2]
# drawing polygons
for (i in 1:15) {
x1 <- c(x[i],x[i+1],loc[1])
y1 <- c(y[i],y[i+1],loc[2])
polygon(x1,y1,col=cols[i])
}
# drawing the last polygon
polygon(c(x[16],x[1],loc[1]),c(y[16],y[1],loc[2]),col=cols[16])
# drawing letters
b <- c("E","N","W","S")
for (i in 0:3) text((size+par("cxy")[1])*cos(bearing+i*pi/2)+loc[1],
(size+par("cxy")[2])*sin(bearing+i*pi/2)+loc[2],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