【问题标题】:how to control transparency of ppp density plot如何控制ppp密度图的透明度
【发布时间】:2017-07-28 11:33:55
【问题描述】:

我正在尝试使用分层方法来覆盖几个 spatstat 空间对象。所有这些对象都用于同一个窗口。我有一个来自 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)图添加一点透明度。

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

谢谢。

【问题讨论】:

  • 请提供示例代码,我们可以很容易地尝试修改它以增加透明度。
  • 感谢您的回复。我添加了一个示例代码。

标签: spatstat


【解决方案1】:


首先是原帖中的命令:

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 更多/更少透明度:

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)

【讨论】:

  • 非常感谢。通过这个答案,我还了解了 NULL 参数和 Kovesi 映射。
猜你喜欢
  • 2012-03-28
  • 1970-01-01
  • 2011-09-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-06
  • 1970-01-01
  • 2017-11-28
相关资源
最近更新 更多