Change raster panel titles using levelplot

I use RasterVis and levelplot to create a trellised graph of some rasters. I am currently approved for most things, but I would like to change the title for each panel from the file name to the selected line (the file name is confusing and long, I want to use only a year, like "2004").

Looking at the levelplot page , this will mean that the levelplot is looking for some settings according to the 'useRaster' argument, or it goes to panel.levelplot or panel.levelplot.raster , but I try to use these last functions.

Any help is much appreciated, here are some sample code;

require(rasterVis)

layers <- c(1:4)
s2 <- stack()

for (i in layers) {
  r <- raster(nrows=100, ncols=100,ext)
  r[] <- sample(seq(from = 1, to = 6, by = 1), size = 10000, replace = TRUE)
  rasc <- ratify(r)
  rat <- levels(rasc)[[1]]
  rat$legend <- c("A","B","C","D","E","F")
  levels(rasc) <- rat
  s2 <- stack(s2, rasc)
}

levelplot(s2, col.regions=rev(terrain.colors(6)),main = "example")

, , , "layer.1.1" "2004" .. 2007

+4
1
require(rasterVis)

layers <- c(1:4)
s2 <- stack()

for (i in layers) {
  r <- raster(nrows=100, ncols=100)
  r[] <- sample(seq(from = 1, to = 6, by = 1), size = 10000, replace = TRUE)
  rasc <- ratify(r)
  rat <- levels(rasc)[[1]]
  rat$legend <- c("A","B","C","D","E","F")
  levels(rasc) <- rat
  s2 <- stack(s2, rasc)
}
levelplot(s2, col.regions=rev(terrain.colors(6)),main = "example", names.attr=2004:2007)

enter image description here

p.strip <- list(cex=1.5, lines=1, col="blue, fontfamily='Serif')

levelplot(s2, col.regions=rev(terrain.colors(6)), main = "example",
          names.attr=2004:2007, par.strip.text=p.strip)

enter image description here

+4

Source: https://habr.com/ru/post/1623244/


All Articles