2

it's my first time using the spatstat package, so I would like some advice. I am attempting to plot coordinate data into a irregular polygon area (format .shp), to calculate spatial analysis like Ripley's K. How can I add an irregular polygon area as a plot? How can I merge the .ppp data from the coordinates into the polygon area? I have used the following codes:

Converting the coordinate data to .ppp format

library(spatstat)
library(sp)
library(maptools)

tree.simu <- read.table("simulation.txt", h=T)
tree.simu.ppp <-ppp(x=tree.simu$X,y=tree.simu$Y,window=owin(c(min(tree.simu$X),max(tree.simu$X)),c(min(tree.simu$Y),max(tree.simu$Y))))
plot(tree.simu.ppp)

With this function I am considering the plot area as the max and min valeu of the coordinates. I would like to put the polygon boundary as the plot.

Ploting the irregular polygon area

area <- readShapePoly("Area/Fragment.shp")
plot(area)
plot(tree.simu.ppp, add=T)

or

points(tree.simu.ppp)

The package accept the last function but, when I try to plot both files together, seems like that the .shp file it is fill the whole area. I can't visualize the coordinates data.

Thank you, I really appreciate your help!

ps.: If you know any material with those question, please I would be happy to take a look

  • 1
    There must be a problem with your dataset, as this should work. Can you upload `simulation.txt` and the set of files that constitute `Fragment.shp` somewhere and post a link in your question? Otherwise it's just guesswork. For example, are you sure that the bounding box for `tree.simu` overlaps with the bounding box for `area`?? – jlhoward Jun 26 '14 at 18:04
  • Yes, please post the data so we can see what goes wrong. Maybe you can find some inspiration in the shapefiles vignette of spatstat: http://www.cran.r-project.org/web/packages/spatstat/vignettes/shapefiles.pdf – Ege Rubak Jun 26 '14 at 20:47
  • Hi Jlhoward, I hope this workout. The fragment area and the simulate coordinates data are on the following link: https://drive.google.com/folderview?id=0B_cWshGkkAzjbHBnemNuMzh1Q1k&usp=sharing if you need something else, please let me know. – Renzo Ferreira Jun 27 '14 at 04:58

1 Answers1

1

This is indeed due to inconsistent bounding boxes as conjectured in the comment by @jlhoward. Your points are in [273663.9, 275091.45] x [7718635, 7719267] while the polygon is contained in [-41.17483, -41.15588] x [-20.619647, -20.610134].

Assuming the coordinates were indeed consistent with the window the correct way way of getting it into a ppp object would be:

library(spatstat)
library(sp)
library(maptools)

area <- readShapePoly("Area/Fragment.shp")
area <- as(area, "owin")
tree.simu <- read.table("simulation.txt", h=T)
tree.simu.ppp <-ppp(x=tree.simu$X,y=tree.simu$Y,window=area)

However, you will get a warning about your points being rejected since they are outside the window, and the object will contain no points.

Ege Rubak
  • 4,347
  • 1
  • 10
  • 18