r - 使用 levelplot 更改光栅面板标题

标签 r raster levelplot rastervis

我正在使用 RasterVis 和 levelplot 制作一些栅格的网格图。我目前对大多数事情都可以,但我想将每个面板的标题从文件名更改为选定的字符串(文件名很复杂而且很长,我只想使用一年,例如“2004”)。

看着levelplot page ,这将表明 levelplot 根据参数“useRaster”寻找一些设置,要么转到 panel.levelplot or 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)
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

关于r - 使用 levelplot 更改光栅面板标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34652580/

相关文章:

r - 在r中的栅格层上绘制空间点

r - 允许 map 上权重重的点压倒其他权重低的点的选项

r - 如何从 Fortran 调用 R 函数?

r - 如何转换从 CSV 读取为纬度/经度坐标的地理空间数据以匹配从 SHP 读取的数据?

python - 列操作 R

python - 传递超过 23 个输入文件时 gdal_calc amin 失败

r - 安装 Xcode 9 后缺少 "libsystem_darwin.dylib"

带有离散色标的光栅图,用于负值和正值 R

r - 更改 R 中 levelplot 的宽度

r - 在格子图中添加/代替背景颜色使用图案