# NOT RUN {
library(sp)
data(meuse)
coordinates(meuse) <- ~x+y
# Weighted KDE using cadmium and spatial locations
cadmium.kde <- sp.kde(x = meuse, y = meuse$cadmium, bw = 1000, n = 5000,
standardize = TRUE, scale.factor = 10000 )
# Unweighted KDE (spatial locations only)
pt.kde <- sp.kde(x = meuse, bw = 1000, standardize = TRUE, n = 5000,
scale.factor = 10000 )
# Plot results
par(mfrow=c(1,2))
plot(cadmium.kde, main="weighted kde")
points(meuse, pch=20, col="red")
plot(pt.kde, main="Unweighted kde")
points(meuse, pch=20, col="red")
# Using existing raster
library(raster)
data(meuse.grid)
coordinates(meuse.grid) = ~x+y
proj4string(meuse.grid) <- CRS("+init=epsg:28992")
gridded(meuse.grid) = TRUE
meuse.grid <- raster(meuse.grid)
cadmium.kde <- sp.kde(x = meuse, y = meuse$cadmium, newdata = meuse.grid, bw = 1000,
standardize = TRUE, scale.factor = 10000 )
plot(cadmium.kde, main="weighted kde")
points(meuse, pch=20, cex=0.5, col="red")
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab