我有一个示例数据集(名为“data”),其坐标如下所示(在 CRS 5321 中投影):
longitude latitude
430547.6 7208993
404139.3 7212760
411915.5 7232663
430181.8 7239410
431756.6 7245202
436880.9 7267675
453830.3 7216400
465987.5 7210260
473772.0 7180114
478228.2 7182945
我正在尝试计算该数据集的起始范围。我使用 R 中的 ks 包选择了 95% kde。计算此起始范围的代码如下所示:
library(ks)
h1 <- Hpi(data, pilot = "samse", binned = T)
home.range <- kde(data, H = h1)
这将返回一个列表类型的对象。我现在想绘制我的家庭范围,但它目前是错误的对象类型。如何将其转换为可以绘制的对象(例如,作为具有 x-y 坐标的矩阵)?
将以下行添加到您的代码中(这些需要 grDevices 包):
cont = contourLevels(kernPI1, cont = 95) # Can modify the 95 if you want something smaller than a 95% home range
line = contourLines(x = kernPI1$eval.points[[1]], y =
kernPI1$eval.points[[2]],
z = kernPI1$estimate,
level = cont)
# Extract x y coordinates
x<-line[[1]][["x"]]
y<-line[[1]][["y"]]
# Convert to dataframe and plot points
line2<-data.frame(x,y)
plot(line2)