I have 2 rasters stacked together:
我有两个光栅堆在一起:
library(rasterVis)
r1 <- raster(system.file("external/test.grd", package="raster"))
r2 <- r1 / 2
r.stack <- stack(r1, r2)
Since I would like to highlight some areas later for each specific layer in the stack, I create two point datasets based on the raster values:
由于稍后我想为堆栈中的每个特定层突出显示一些区域,所以我基于光栅值创建了两个点数据集:
pts1 <- rasterToPoints(r1, spatial=T)
idx <- which(as.data.frame(pts1)[, 1] >= 400)
pts1 <- pts1[idx, 1]
pts2 <- rasterToPoints(r2, spatial=T)
idx <- which(as.data.frame(pts2)[, 1] >= 400)
pts2 <- pts2[idx, 1]
Now, I would like to plot the raster stack with levelplot from rasterVis in R. I would also like to overlay r1 with pts1 and r2 with pts2.
现在,我想用r的水平图来绘制光栅堆栈,我也想用pts1和r2来覆盖r1和pts2。
However, as soon as I add one point dataset, it is used for both layers:
但是,只要我添加一个点数据集,它就可以用于两个层:
levelplot(r.stack) + layer(sp.points(pts1, pch=20, cex=0.1, col="black"))
How can I use specific point datasets with specific layers while still using raster stacks?
如何在使用光栅堆栈的同时使用具有特定层的特定点数据集?
I would like to avoid making my own subplot by plotting each layer with its' specific point dataset alone followed by using print.trellis. I tried it, but the result is just inferior compared to levelplot with raster stacks.
我想避免生成我自己的子图,通过单独使用它的“特定点数据集”来绘制每一层,然后使用print.trellis。我试过了,但结果比用光栅堆叠的等级更差。
Any idea on how to achieve that?
你知道怎么做吗?
1 个解决方案
#1
4
With the panel.number
function you can subset your data according to the panel you are located:
与面板。数字功能你可以根据你所在的面板对你的数据进行子集划分:
pts <- list(pts1, pts2)
levelplot(r.stack) +
layer(sp.points(pts[[panel.number()]],
pch=20, cex=0.1, col="black"))
#1
4
With the panel.number
function you can subset your data according to the panel you are located:
与面板。数字功能你可以根据你所在的面板对你的数据进行子集划分:
pts <- list(pts1, pts2)
levelplot(r.stack) +
layer(sp.points(pts[[panel.number()]],
pch=20, cex=0.1, col="black"))