0

Please see below image. This image is created by first converting a two-column data frame into a study window (call it study_win) using as.owin, and then plotting another two-columns data-frame (call it study_points)on top of the window.

It is clear that the points are lying inside the window! However when I call

ppp(study_points[,1],study_points[,2],win = study_window) 

it says that most of my points are rejected as lying outside the window. Could someone tell me what is going on?

Thanks!

enter image description here

nobody
  • 815
  • 1
  • 9
  • 24
  • Please make a reproducible example. I see at least one point outside of the window on the plot, and there may be more points not plotted at all given the XY limits to the graph. – Andy W Sep 24 '15 at 16:59
  • I am afraid I cannot make a reproducible example.. this is a very complicated window and it is defined by a big csv file. There are around 185 points and when I call ppp it says 180 points are "illega" and "rejected as lying outside the window" – nobody Sep 24 '15 at 17:06
  • Not much anyone can do then besides guess. Are you sure your window is defined correctly, and isn't the obverse of the area you show in your plot (i.e. what we see is the hole, not the outline of the window)? – Andy W Sep 24 '15 at 18:14

2 Answers2

1

First you could have taken a step back to check that the window object study_window was what you intended. You could have plotted or printed this object in its own right. A plot of study_window would show (and you can also see this in the plot that you supplied in the question) that the boundary of the window is a disconnected scatter of points, not a joined-up polygon. A printout of study_window would have revealed that it is a binary pixel mask, with a very small area, rather than a polygonal region. The help for as.owin explains that, when as.owin is applied to a dataframe containing columns of x,y coordinates, it interprets them as pixel coordinates of the pixels that lie inside the window.

So,what has happened is that as.owin has created a window consisting of one pixel at each of the (x,y) locations in the data frame. That's not what you wanted; the (x,y) coordinates were meant to be the vertices of a polygonal boundary.

To get the desired window, do something like study_window <- owin(poly=df) where df is the data frame of (x,y) coordinates of vertices.

To do it all in one step, type something like mypattern <- ppp(x, y, poly=df) where x and y are the vectors of coordinates of the points in the window.

0

so I solved the problem by using the "owin" and specify the region to be polygon; instead of "as.owin". I have no idea the difference between owin and as.owin, but I am just glad it worked...

nobody
  • 815
  • 1
  • 9
  • 24
  • The method `as.owin.dataframe` is used to import a window in pixel format. The help file says the input should be: "A ‘data.frame’ with exactly two columns. Each row of the data frame contains the x and y coordinates of a pixel that lies inside the window." – Ege Rubak Sep 25 '15 at 12:16
  • this is exactly what I passed to as.owin -- a data frame with two columns. I suspect that as.owin creates a binary mask, which means only pixels that coincide exactly with any of the rows in the data frame are considered to be "inside the window". This is only my guess however.. – nobody Sep 25 '15 at 14:48
  • 1
    This was what I was trying to say. When you pass the corners of a polygon to `as.owin.dataframe` these will be interpreted as individual pixels that are part of the window and everything else is outside the window. If you e.g. define the corners of a triangle `d = data.frame(x=c(0,1,1), y=c(0,1,3))` and do `as.owin(d)` you get a 2x4 pixel window where the 3 pixels (0,0), (1,1) and (1,3) are inside the window and the 5 pixels (0,1), (0,2), (0,3), (1,0), and (1,2) are outside the window. – Ege Rubak Sep 26 '15 at 15:39