I'm new to spatial analysis using R. I'm trying to calculate daily home ranges (MCP 100, later 95 and 50 %) using mainly the adehabitatHR package in R. I used a script provided by my colleague and it worked for her all the time. Now when I'm running it, it works but I receive e-xx values which is way too small. I don't really see where it goes wrong, I assume it has something to do with the projection, but I'm way too inexperienced to know which should be better.
You can see the code below. Maybe someone knows how to fix this?
library (adehabitatHR)
library (sp)
library (scales) # helps make Polygons partly transparent using the alpha argument below
library(dplyr)
# Read data frame into R
tab1<-read.csv(file="animals.csv",sep=",",header=TRUE)
# Remove two rows with NA´s
tab1 <- tab1 [!is.na(tab1$x_) & !is.na(tab1$y_),]
# Only include three columns (AnimalID + Exp, x and y coordinates) for making MCP´s
# Creating new ID to group days and AnimalID
tab2 <- tab1 [, c("id", "x_", "y_", "day", "month", "year")] # week, month, day + month
tab2$Time <- paste(tab2$day, tab2$month, sep= " ") # day + month
tab2$Time2 <- paste(tab2$Time, tab2$year)
tab2$Mix <- paste(tab2$AnimalID, tab2$Time2, sep= " ") # id + time
tab3 <- tab2 [, c("Mix", "x_", "y_")]
tibble(tab3)
# Check in tab2 which Animal has less than 5 GPS location
tab4 <- tab3 %>%
group_by(Mix) %>%
summarise(n = n())
# Filter data with less than 5
tab5<-filter(tab4, n > 5)
tab6<-filter(tab4, n < 5)
# Remove rows from data set which have less than 5 GPS location
tab7 <- tab3 %>%
filter(!grepl(" 31 May 2019", Mix))
tab8 <- tab7 %>%
filter(!grepl(" 29 Jun 2019", Mix))
# Create a SpatialPointsDataFrame by defining the coordinates
coordinates(tab8) <- c("x_", "y_")
str(tab8)
# Set the coordinate reference system, (CRS)
# The sample data are UTM points in WGS84 from zone 33N
proj4string(tab8) <- CRS( "+proj=utm +zone=33N +datum=WGS84 +units=m +no_defs" )
animals.mcp <- mcp(tab8[, "Mix"], percent = 100, unin = "m", unout = "m2")
as.data.frame(animals.mcp)
Output Data looks like this:
id area
1 Dec 2019 1 Dec 2019 5.180087e-03
1 Feb 2020 1 Feb 2020 7.171711e-04
1 Jan 2020 1 Jan 2020 1.692209e-03
1 Jul 2019 1 Jul 2019 3.384402e-07
1 Jun 2019 1 Jun 2019 1.829374e-01
1 Nov 2019 1 Nov 2019 7.794313e-04
...
Thanks in advance!
So I was able to solve it by adding
coordinates(tab7) <- c("x_", "y_")
proj4string(tab7) <- CRS("+init=epsg:4326")
tab8 <- spTransform(tab7, CRS("+proj=utm +zone=33N +datum=WGS84 +units=m +no_defs"))
So first telling R what coordinate system to use and then project it to the necessary area.
Hope this helps others with the same question!