Skip to content
Prev 23301 / 29559 Next

sp and latticeExtra: add colorbar for layer drawn 'under'

Ben,
as a follow up, it also works the other way round, which is more intuative:

pols <- spplot(spdfbb,
                colorkey = FALSE,
                sp.layout = list(b = list('sp.polygons', qa, col = 
'grey', first = FALSE)))

rst <- spplot(R)

combo <- rst + as.layer(pols)
combo

I am not sure why SpatialPolygons* objects get rendered via levelplot.
In general, the crux with lattice/latticeExtra is that all layers 
essentially get amalgamated into one list object and hence the style 
settings for the plot are taken from the first object (rst). So if you 
were to draw pols first, the relevant colorkey specification would be 
taken from pols:

pols2 <- spplot(spdfbb,
                 colorkey = list(col = heat.colors(101), width = 1,
                                 at = seq(0, 30, length.out = 100),
                                 space = "top"),
                 sp.layout = list(b = list('sp.polygons', qa, col = 
'grey', first = FALSE)))

pols2

combo2 <- pols2 + as.layer(rst, under = TRUE) #colorkey now taken from pols2
combo2

combo3 <- rst + pols2 #same as above as colorkey is taken from rst
combo3

Best
Tim
On 29.08.2015 02:32, Ben Tupper wrote: