【问题标题】:ScatterPlot between two rasters, giving color from a third raster两个栅格之间的散点图,从第三个栅格给出颜色
【发布时间】:2014-10-02 07:34:21
【问题描述】:

我正在绘制两个栅格数据,生成下面的图像。

我想用取自第三个栅格数据的变量(具有相同的 bbox、像素大小等)为图中的每个点着色。 来自 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

非常感谢!

【问题讨论】:

  • 本质上,您只想以不同(特定?)颜色覆盖第三个栅格中的点?
  • 嗨,罗曼,没错。颜色应由第三个栅格的栅格值给出。第三个栅格的数字很少(大约五个)。
  • 你能做一个可重现的例子吗?
  • Oscar Perpiñán 提供的应该没问题,我猜。

标签: r scatter-plot raster


【解决方案1】:

使用中定义的xyplot 方法 rasterVis 您可以使用 RasterStack 的层,就好像它们是 a 的列一样 data.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)

【讨论】:

  • 谢谢奥斯卡。通过使用您的示例,我还发现了以下解决方案: my.colors
猜你喜欢
  • 2021-07-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-08-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多