Partition coordinates into quantile polygons
Arguments
- x
numeric/sf/SpatVector. x-coordinates (if numeric).
- y
numeric. y-coordinates.
- quantiles
numeric vector. Quantiles.
See also
Other Parallelization:
par_fallback()
,
par_grid()
,
par_group_grid()
,
par_hierarchy()
,
par_make_grid()
,
par_make_gridset()
,
par_merge_grid()
,
par_multirasters()
Examples
library(terra)
random_points <-
data.frame(x = runif(1000, 0, 100), y = runif(1000, 0, 100))
quantiles <- par_def_q(4L)
qpoly <- par_cut_coords(random_points$x, random_points$y, quantiles)
clustered_points <-
data.frame(x = rgamma(1000, 1, 1), y = rgamma(1000, 4, 1))
qpoly_c <- par_cut_coords(clustered_points$x, clustered_points$y, quantiles)
par(mfcol = c(1, 2))
plot(qpoly)
plot(qpoly_c)
par(mfcol = c(1, 1))
cvect <- terra::vect(clustered_points, geom = c("x", "y"))
plot(cvect)
plot(qpoly_c, add = TRUE, col = "transparent", border = "red")
qcv <- intersect(cvect, qpoly_c)
table(qcv$CGRIDID)
#>
#> 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#> 56 62 68 64 73 58 56 63 60 60 62 68 61 70 64 55
sum(table(qcv$CGRIDID)) # should be 1000
#> [1] 1000