I've been using spatstat to analyse point patterns in R. Here's an example to put this in context:
library(spatstat)
library(maptools) # to convert sp class to ppp
Some point data:
set.seed(1985)
x <- rnorm(20)
y <- rnorm(20)
p <- SpatialPoints(coords = matrix(c(x, y), ncol = 2))
plot(p)
The challenge is to find the kernel density at each point, not in a continuous field
aggregated as cells in a raster image, as calculated by density
from spatstat:
p <- as.ppp(p)
d <- density.ppp(p, sigma = 0.3)
plot(d)
From this one can identify clusters and other useful things, but it does not provide imediate insight into the point that has the highest dot density. So this is a two-part question:
- How to extract the coordinates of the pixel with the highest density in
d
? - Is there a way to calculate the kernel density only for the 20 points in
p
?
p=as.ppp(p)
fails (R 3.1.1, latest spatstat) "Can't interpret X as a point pattern"... – Spacedman Sep 25 '14 at 9:42