0
votes

I am trying to use the layered methods to overlay few spatstat spatial objects. All these objects are for the same window. I have an im layer (density) from a ppp. I want to make this layer a bit transparent in order to have a better visibility of the other objects in the layered object.

How can I control the transparency of this density plot (im)? Is there something like alpha or transparency parameter for the plot.im ?

UPDATE:

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)

enter image description here

Here , I have plotted 3 layers. As you can see the density plot has very dark blues and reds. Yes, I can plot lines and points with different colours to make them visible, but it would nice to do simple stacked line, point plots and add a little bit of transparency to the density (im) plots.

The purpose is just to avoid complex customized plot colours and to explain to colleagues.

thank you.

1
Please provide example code, so we can easily try to modify it to add transparency.Ege Rubak
Thank you for your reply. I have added a sample code.BKS

1 Answers

0
votes


First the commands from the original 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)

You need to provide a different colourmap to plot.im. There are two ways you can do this:

  1. Plot each layer individually using add = TRUE for subsequent layers and provide the colour map when you plot the im object.
  2. Pass a list of plot arguments when you plot the layered object you have created above.

I find the first option easier for illustration, so I will do that first. The default colourmap of spatstat is the 29th Kovesi colour sequence (?Kovesi for more details on these sequences):

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

To add transparency you can use to.transparent with your choice of fraction for more/less transparency:

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

Now you just need to use this as your colourmap:

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

To do it with the layered object you have to make a list of plot argument lists (containing NULL if you don't have additional arguments):

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