How to add a scalebar to a single panel in spplot
<p>I have a panel of eight maps from a RasterStack, and wish to add a 100km scale bar to the plot. I have used <code>sp.layout</code> within the <code>spplot</code> function to add SpatialLines objects on top of the rasters, and assumed that the same would be possible with scalebars (or north arrows), but I can't get anything to work.</p>

<p>The code I am using is:</p>

<pre><code>library(sp)
library(raster)
library(grid)

spplot(rasterstack, layout=c(2,4),
       names.attr=c("a", "b", "c", "d", "e", "f", "g", "h"),
       between=list(x=1, y=1),
       at=seq(0,1000,by=100),
       col.regions=colorRampPalette(c("grey90","yellow4","green4"))(100),
       par.strip.text=list(cex=2.5),
       scales=list(draw=F),
       colorkey=list(labels=list(labels=seq(0,1,by=0.25),
                                 at=seq(0,1000,by=250),
                                 width=10, cex=2.5)),
       sp.layout=list(list(country, first=FALSE), # add country borders
                      list(spatiallines, lwd=1.5, col=4)))
# Label vertical colorkey
grid::grid.text('Probability of occurrence', y=unit(0.5,"npc"), x=unit(0.95,"npc"), rot=90, gp=gpar(cex=3, font=2))
</code></pre>

<p>Where <code>rasterstack</code> is a RasterStack with 8 layers, and the values in each cell range from 0 to 1000, and <code>country</code> and <code>spatiallines</code> are SpatialLines* objects</p>

<p>I've come across various functions for adding scale bars, e.g. <code>layout.scale.bar()</code>, <code>maps::map.scale()</code> and <code>scalebar()</code>, but I can't work out how to incorporate them into the <code>spplot</code> code I am using. I've tried adding them as arguments in <code>spplot</code> or as lists within the <code>sp.layout=list()</code> argument, but neither works.</p>

<p>Thanks!</p>