1

I would like to plot a ppp object from a particle analysis in ImageJ from a greyscale image with size imageSizeX, imageSizeY of point objects Particles$X, Particles$Y in flipped Java coordinates (y0 = top-left). I have a kind of working solution (example with customization):

library(spatstat)

X <- ppp(Particles$X, Particles$Y, c(0, imageSizeX), c(0, imageSizeY))
plot(x = 0, y = 0, xlim = c(0, imageSizeX), ylim = c(imageSizeY, 0), type = "n", main = "Density", 
    asp = 1, axes = F, xlab = "X", ylab = "Y")
plot(density(X), xlim = c(1, imageSizeX), ylim = c(imageSizeY, 0), add = T)
plot(X, axes = TRUE, xlim = c(1, imageSizeX), ylim = c(imageSizeY, 0), add = T)
axis(1)
axis(2, las = 2)

which results in the following plot (which omits the legend):

enter image description here

However I need to create an empty plot command with the flipped coordinates (ylim = c(imageSizeY, 0)) and then have to add the spatstat plots.

If I try to plot:

library(spatstat)
X <- ppp(Particles$X, Particles$Y, c(0, imageSizeX), c(0, imageSizeY))
plot(density(X), xlim = c(1, imageSizeX), ylim = c(imageSizeY, 0))
plot(X, axes = TRUE, xlim = c(1, imageSizeX), ylim = c(imageSizeY, 0), add = T)
axis(1)
axis(2, las = 2)

the coordinates are not plotted flipped (ylim = c(imageSizeY, 0)):

enter image description here

Is there a way to flip the plot coordinates in spatstat without a first defining plot command?

Marcel
  • 502
  • 3
  • 11

1 Answers1

0

This is a bug in plot.ppp. I have fixed it in the current development version of spatstat, version 1.46-1.010 available from the spatstat repository on GitHub

In the current version of spatstat on CRAN (1.46-1) the plot method for windows, plot.owin, does recognise xlim, ylim as you would like, while plot.ppp does not. So if X is a point pattern, you can do

W <- Window(X)
plot(W, xlim=rev(W$xrange), main="The title")
plot(X, add=TRUE, ...)
Adrian Baddeley
  • 1,956
  • 1
  • 8
  • 7