我正在绘制两个栅格数据,生成下图。
我想使用取自第三个栅格数据的变量(具有相同的框、像素大小等)为图中的每个点着色。 R 用户有什么想法吗?这个操作在绘制数据集中的数据时非常容易,但我不知道栅格......
这里我附上生成图像的代码(经过简化,我认为您不需要所有绘图参数,例如 abline、xlab 等):
plot(mask(raster1, my_mask,maskvalue=0), #first raster, masked by my_mask
mask(raster2, my_mask,maskvalue=0), #second raster, masked by my_mask
col = alpha('black', 0.1), #the current color scheme
)
raster3 #raster with categorical variable,
#that should give the colors to the points in the graph
非常感谢!
最佳答案
使用中定义的xyplot
方法
rasterVis
您可以使用 RasterStack 的层,就好像它们是
数据.frame
。因此,它们可以是公式或
groups
参数。
例如,
library(raster)
library(rasterVis)
f <- system.file("external/test.grd", package="raster")
r <- raster(f)
r2 <- r + 500 * init(r, rnorm)
## categorical variable
r3 <- cut(r, 3)
s <- stack(r, r2, r3)
names(s) <- c('r', 'r2', 'r3')
xyplot(r ~ r2, groups = r3, data = s,
auto.key = list(space = 'right'),
alpha = 1)
关于r - 两个栅格之间的散点图,给出第三个栅格的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26156203/