Sorry, for my newb question. I'm still learning how to conduct spatial analyses in R. I realize this question has been previously asked (here).
Goal: I'm unable to run this code with simulated data within the parameters specifically for my longitude (X) values (see line: 24). I would like to plot home range with simulated data (below).
Error: "Error in getverticeshr.estUD(x[[i]], percent, ida = names(x)[i], unin, : The grid is too small to allow the estimation of home-range. You should rerun kernelUD with a larger extent parameter"
# 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)