Simulate minefields with two samples in the same plot in R

89 views Asked by At

I am trying to simulate a minefield by plotting two Poisson distributed samples in the same plot, one with a higher intensity and smaller area than the other. This is the minefield and the other is just noise (stones, holes, metal) seen as points. I cannot get R to plot the points with the same units in the axis. Whatever I do, the points span the entire plot, even though I only want the X points to cover a quarter of the plot. My R-code is just the following:

library(spatstat)
Y = rpoispp(c(5),win=owin(c(0,10),c(0,10)))
X = rpoispp(c(10),win=owin(c(0,5),c(0,5)))

Please let me know if you can help me.

1

There are 1 answers

0
tegancp On

My guess is that you are doing something like:

> plot(Y)
> plot(X)

to plot the points.

The problem with this is that the default behavior of the plot function for the class ppp (which is what the rpoispp function returns) is to create a new plot with just its points. So the second plot call essentially erases the first plot, and plots its own points in a differently scaled window. You can override this behavior by setting the option add=TRUE for the second plot. So the code

> plot(Y)
> plot(X, add=TRUE, cols="red")

should get you something like: plot of two poisson point patterns

Check out the docs (help(plot.ppp)) for more explanation and other options to prettify the plot.