对不起,我的新手问题。我仍在学习如何在 R 中进行空间分析。我意识到这个问题以前曾被问过(这里)。
目标:我无法使用参数中的模拟数据运行此代码,专门针对我的经度 (X) 值(参见第 24 行)。我想用模拟数据(下)绘制家庭范围。
错误:“getverticeshr.estUD(x[[i]], percent, ida = names(x)[i], unin, 中的错误:网格太小,无法估计主范围。您应该重新运行 kernelUD更大范围参数"
# 1. Packages
library(adehabitatHR) # Package for spatal analysis
# 2. Empty Dataframe
points <- data.frame(ID = double())
XY_cor <- data.frame(X = double(),
Y = double())
# 3. Assigning values (this will be our spatial coordinates)
set.seed(17)
for(i in c(1:100)){
if(i >= 50){points[i, 1] <- 1}
else {points[i, 1] <- 2}
XY_cor[i, 1] <- runif(1, -78.86887, -78.86440) ## error is here!
XY_cor[i, 2] <- runif(1, 0.958533, 0.960777)}
# 4. Transform to SpatialDataframe
coordinates(points) <- XY_cor[, c("X", "Y")]
class(points)
# 5. Domain
x <- seq(-80.0, -77.0, by=1.) # resolution is the pixel size you desire
y <- seq(-200, 200, by=1.)
xy <- expand.grid(x=x,y=y)
coordinates(xy) <- ~x+y
gridded(xy) <- TRUE
class(xy)
# 6. Kernel Density
kud_points <- kernelUD(points, h = "href", grid = xy)
image(kud_points)
# 7. Get the Volum
vud_points <- getvolumeUD(kud_points)
# 8. Get contour
levels <- c(50, 75, 95)
list <- vector(mode="list", length = 2)
list[[1]] <- as.image.SpatialGridDataFrame(vud_points[[1]])
list[[2]] <- as.image.SpatialGridDataFrame(vud_points[[2]])
# 9. Plot
par(mfrow = c(2, 1))
image(vud_points[[1]])
contour(list[[1]], add=TRUE, levels=levels)
image(vud_points[[2]])
contour(list[[2]], add=TRUE, levels=levels)
# 10. Get vertices
vkde_points <- getverticeshr(kud_points, percent = 50,
unin = 'm', unout='m2')
plot(vkde_points)