Search code examples
r3dspatialspatstat

Is it possible to add marks to a 3D point pattern using SpatStat in Rstudio?


I am using spatstat software to analyse the spatial relationship between cells. I have used this in the past for 2D and it was fine. I am now using it for 3D analysis from confocal images.

My problem is that I am unable to plot the resultant point pattern with different marks. I am able to assign the marks (cell type) to each point and plot the 3D point pattern. However the marks do not appear on the plot as different characters.

Series6 <-pp3(Series6[,5], Series6[,6],Series6[,7],box3(c(0,775),c(0,775),c(0,30)), marks = Series6[,8])

The resultant plot: 3D Plot

I have tried it with 2D point patterns and it works fine displaying a different character for each mark. This makes me think that the marks feature isn't compatible with 3D point patterns. I would be grateful if anyone had any tips.


Solution

  • A three dimensional point pattern (class pp3) can have marks. Your code has successfully assigned marks to the points. You could check this by typing head(as.data.frame(Series6)) which would show the coordinates and marks of the first few points.

    The problem is that the plot method, plot.pp3, does not display the marks. This feature is not yet implemented.

    I will take this question as a feature request for spatstat.

    In the meantime, you can get the desired effect by splitting the point pattern into subsets with different marks (assuming the marks are categorical) and plotting each subset in turn. Here is a function to do that:

    plotbymark <- function(X, cols=NULL, chars=NULL, main="") {
       require(spatstat)
       stopifnot(is.pp3(X))
       stopifnot(is.multitype(X))
       Y <- split(X, un=TRUE)
       m <- length(Y)
       mm <- seq_len(m)
       if(is.null(cols)) cols <- mm
       if(is.null(chars)) chars <- mm
       for(i in mm) {
          plot(Y[[i]], col=cols[i], pch=chars[i], add=(i > 1), main=main)
       }
       explain <- data.frame(type=names(Y), col=cols, pch=chars)
       return(invisible(explain))
     }