如何控制 ppp 密度图的透明度

how to control transparency of ppp density plot

我正在尝试使用分层方法来覆盖几个 spatstat 空间对象。所有这些对象都是针对同一个 window。我有一个来自 ppp 的 im 层(密度)。我想让这个层有点透明,以便更好地看到分层对象中的其他对象。

如何控制此密度图 (im) 的透明度? plot.im 是否有类似 alpha 或透明度的参数?

更新:

library(spatstat)
pipes=simplenet
plot(pipes)
point_net = as.ppp(runifpoint(10, win = Window(pipes)))
point_surface = density(point_net)
plot(point_surface)
layers= layered(point_surface, point_net, pipes)
plot(layers)

在这里,我画了3层。如您所见,密度图具有非常深的蓝色和红色。是的,我可以绘制不同颜色的线和点以使它们可见,但最好是绘制简单的堆叠线、点图并为密度 (im) 图添加一点透明度。

目的只是为了避免复杂的自定义绘图颜色和向同事解释。

谢谢。


首先是来自原始 post 的命令:

library(spatstat)
pipes=simplenet
point_net = as.ppp(runifpoint(10, win = Window(pipes)))
point_surface = density(point_net)
layers= layered(point_surface, point_net, pipes)
plot(layers)

您需要为 plot.im 提供不同的颜色图。那里有两个 你可以这样做的方法:

  1. 使用 add = TRUE 单独绘制每一层用于后续 图层并在绘制 im 对象时提供颜色图。
  2. 在绘制 layered 对象时传递一个绘图参数列表 以上已创建。

我觉得第一个选项更容易说明,所以我会这样做 第一的。 spatstat 的默认色图是第 29 个 Kovesi 颜色 序列(?Kovesi 有关这些序列的更多详细信息):

def_col <- Kovesi$values[[29]]
head(def_col)
#> [1] "#000C7D" "#000D7E" "#000D80" "#000E81" "#000E83" "#000E85"

要增加透明度,您可以使用 to.transparent 选择 fraction more/less 透明度:

def_col_trans <- to.transparent(def_col, fraction = 0.7)
head(def_col_trans)
#> [1] "#000C7DB3" "#000D7EB3" "#000D80B3" "#000E81B3" "#000E83B3" "#000E85B3"

现在您只需要将其用作您的颜色图:

plot(point_surface, col = def_col_trans)
plot(point_net, add = TRUE)
plot(pipes, add = TRUE)

要使用 layered 对象,您必须制作一个绘图列表 参数列表(包含 NULL 如果你没有额外的 参数):

layer_args <- list(list(col = def_col_trans),
                   list(NULL),
                   list(NULL))
plot(layers, plotargs = layer_args)