The spatstat
package makes this easy. Since I don’t know what your data looks like, I’ll start by creating some demo data.
x <- rnorm(327)
y <- runif(327)
Now convert the data into a geospatial format using the ppp()
function from spatstat
.
library(spatstat)
dta <- ppp(x, y, window = owin(c(-5, 5), c(-5, 5)))
Finally, compute the density and then plot the result.
# Compute the density function
dta <- density(dta)
# Plot the density
plot(dta, main = "Density plot of sample dataset")
1
solved hotspots map using kernel density estimation in R