Skip to content
Prev 22831 / 29559 Next

grid.text with rasterVis::layerplot

Hey Tiffany,
what I usually do is to 'loop' through the layers, create one plot each 
and then combine them back together (using Rsenal::latticeCombineGrid()).
As a side-effect this means that you need to specify explicitly how the 
data range is to be color coded using 'at =' as otherwise you will end 
up with a colorkey that is only representative of the first panel (as 
per default each layer will be streched between its min and max values).

So for a reproducible piece of code (taken from the help page of 
rasterVis::levelplot) it would look something like this (it is hard to 
help without a reproducible example):

## to install Rsenal:
## library(devtools)
## instal_github("environmentalinformatics-marburg/Rsenal")
library(Rsenal)
library(rasterVis)

f <- system.file("external/test.grd", package="raster")
r <- raster(f)
s <- stack(r, r+500, r-500)

labs <- c("a.", "b.", "c.")

p_lst <- lapply(seq(nlayers(s)), function(i) {

   levelplot(s[[i]], par.settings = envinmr.theme(),
             at = seq(-500, 2200, 100), margin = FALSE,
             panel = function(...) {
               panel.levelplot(...)
               panel.text(x = 178500, y = 329500,
                          labels = labs[i], adj = c(0, 0))
             })

})

latticeCombineGrid(p_lst)

If you additionally put yout '+ layer(...)' calls inside the lapply, 
they will also be added to each panel.

Cheers,
Tim
On 22.05.2015 21:54, Tiffany Smith wrote: