[R-sig-Geo] grid.text with rasterVis::layerplot
Tim Appelhans
tim.appelhans at gmail.com
Sat May 23 00:32:19 CEST 2015
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:
> Below is a chunk of code that plots a rasterStack with 6 layers; I am trying to put labels a-f in the bottom right corner of each plot. The code below only shows the letter “a”, how do I get different letters to show in the bottom left corner of each of the 6 plots as I use levelplot?
>
> levelplot(positive,par.settings=myTheme,names.attr=c("","","","","",""))+layer(sp.lines(conus))+layer(sp.lines(n.am))+layer(grid.text(c("a.","b.","c.","d.","e.","f."),.95,.1))
>
> Thanks,
> Tiffany
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
--
#####################################
Tim Appelhans
Department of Geography
Environmental Informatics
Philipps Universität Marburg
Deutschhausstraße 12
35032 Marburg (Paketpost: 35037 Marburg)
Germany
Tel +49 (0) 6421 28-25957
http://environmentalinformatics-marburg.de/
More information about the R-sig-Geo
mailing list