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.