I'm trying to obtain the utilization distribution of an animal using the 'move' package in R, specifically using the code line dynBGB
. However, I'm getting this error message:
"> ambito_hogareno <- dynBGB(move_obj, window = extent(move_obj))
Error in h(simpleError(msg, call)) :
error in evaluating the argument 'x' in selecting a method for function 'raster': error in evaluating the argument 'x' in selecting a method for function 'extent': error in evaluating the argument 'ext' in selecting a method for function '.extcalc': argument "ext" is missing, with no default"
I have tried different approaches to change the method of obtaining ext
, but I simply can't run this line of code. Can someone help me with this issue?.
P.D. This is my script:
Install and load the necessary packages
install.packages("move")
install.packages("ggplot2")
library(move)
library(ggplot2)
Read the data from the CSV file
datos <- read.csv("J587_Categorias.csv")
Create a date-time object from the date and time columns
datos$fecha_hora <- as.POSIXct(paste(datos$YEAR, datos$Month, datos$Day, datos$Hour, datos$MIN, datos$Seconds), format = "%Y %m %d %H %M %S")
Remove duplicated records by date and time
datos <- datos[!duplicated(datos$fecha_hora), ]
Sort the data by date and time
datos <- datos[order(datos$fecha_hora), ]
Create a Move object with spatial coordinates and timestamps
move_obj <- move(x = datos$Longitude, y = datos$Latitude, time = datos$fecha_hora)
Check for any discrepancy
if (nrow(move_obj@data) != length(move_obj@data$individual.local.identifier)) {
If there is a discrepancy, create a vector of identifiers with the correct length
new_identifiers <- rep("unnamed", nrow(move_obj@data))
Replace the values in the Move object
move_obj@data$individual.local.identifier <- new_identifiers
}
Correct the datum definition in the coordinate reference system
crs(move_obj) <- "+proj=longlat +datum=WGS84"
Calculate the home range using the dBBMM method
ambito_hogareno <- dynBGB(move_obj, window = extent(move_obj))
Visualize the home range using ggplot2
ggplot() +
geom_polygon(data = as(move_obj, "SpatialPixelsDataFrame"),
aes(x = x, y = y, fill = dynamics), alpha = 0.6) +
scale_fill_gradient(low = "lightblue", high = "darkblue") +
theme_void()