Reputation: 3
Imagine I have a point pattern distribution in a square and all points have marks (i.e. plant trait data). I want to divide this square in f.e. 4 quadrats. Now I am interested in the spatial distribution of the traits, i.e. I need to now which trait occurs in which quadrat. Only counting the number of points per quadrats does not help in this case, i need to know the points + marks. However, quadratcount ignores the marks. The split-function does not really help as one would need to combine the results per quadrat afterwards, that is not really practical.
# let's try the ant-dataset and count ants in 2x2 quadrats
quadratcount(ants, 2,2)
# raw number of points
x
y [-25,389) [389,803]
[334,717] 22 20
[-49,334) 27 28
# let's count the abundance of different groups of marks per quadrat
quadratcount(split(ants), 2,2)
Cataglyphis:
x
y [-25,389) [389,803]
[334,717] 5 3
[-49,334) 9 12
Messor:
x
y [-25,389) [389,803]
[334,717] 17 17
[-49,334) 18 16
[UPDATE]
I would need a dafaframe with the coordinates corresponding to each mark, grouped by quadrats. With extracted x/y values including the marks. I can do it manually, but it is not very elegant. It might look like this:
$q1[(-25, 389), -49, 334)]
x y marks
x y V3
29 275 325 Messor
36 2 267 Messor
39 124 293 Messor
40 197 207 Messor
41 218 297 Messor
42 236 241 Messor
43 298 271 Messor
44 345 239 Messor
45 388 287 Messor
50 289 188 Messor
51 331 145 Messor
66 236 205 Messor
76 326 303 Cataglyphis
80 -7 233 Cataglyphis
83 233 256 Cataglyphis
84 364 239 Cataglyphis
89 324 101 Cataglyphis
$q2[(-25, 389), (334,717)]
x y marks
...
$q3[(389,803), (334,717)]
x y marks
...
$q4[(389,803), (-49,334)]
x y marks
...
Wondering if someone understand my problem, looking forward to any ideas!
Upvotes: 0
Views: 162
Reputation: 2973
It's unclear exactly what you want. The quadratcount
function counts the number of points falling in each sub-region. If you want to retain the actual point coordinates, then quadratcount
is not the appropriate function. You can use methods for split
and cut
to sub-divide the point pattern while retaining the coordinates.
I'll make two guesses.
ants
data):B <- quadrats(ants, 2, 2)
Y <- split(ants, B)
Z <- lapply(Y, as.data.frame)
where B
is a tessellation object (class tess
) specifying the four tiles; Y
is a list containing the four subsets of the point pattern ants
within these four tiles; and Z
is a list of data frames with columns x, y, marks
.
The split-function does not really help as one would need to combine the results per quadrat afterwards, that is not really practical.
If you just want to know, for each tile, the number of points of each type that fall in the tile, you could do
simplify2array(quadratcount(split(ants, 2, 2)))
which produces a 3D array containing these numbers.
Upvotes: 1