我正在使用RasterVis和levelplot来制作一些栅格的格子图.我目前对大多数事情都很好,但是我想将每个面板的标题从文件名更改为选定的字符串(文件名是复杂且长,我只想使用一年,例如'2004').
查看levelplot页面,它会指示levelplot根据参数'useRaster'查找某些设置,要么转到panel.levelplot或panel.levelplot.raster,但我很难使用后面的这些函数.
任何帮助非常感谢,这里是一些示例代码;
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年
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)
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)