# example to be run if terra is present
if(requireNamespace("terra", quietly=TRUE)){
# randomly generated points
x <- rpsphere(100, output="polar")
# bandwidth grid
y <- hexagrid(deg=13)
# output structure
out <- terra::rast(res=5)
# the function
o <- gridensity(x, y, out, trials=7)
# visualize results
terra::plot(o)
points(x, pch=3)
}
Run the code above in your browser using DataLab