1

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!

  • Hi Justine -- welcome! It would help if you could provide some example data as described in this FAQ on how to provide all of the information necessary to get the best answers: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example. Without that it, it will be hard to know for certain. – mikebader Sep 15 '21 at 19:06
  • It looks like you are correct that the projection is the likely culprit. Fortunately, you can just convert the area units from their measured units to your desired units (e.g., from m^2 to km^2 by dividing by `1e6`). – mikebader Sep 15 '21 at 19:08
  • Thank you! I was able to resolve it, not sure if it's an elegant way but it's working now: `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 basically had to tell him it's WGS84 and then project it to my area. Exported in GIS and it looks good now! – Justine Güldenpfennig Sep 16 '21 at 20:21
  • That's great! I'm so glad =) You should put what you wrote above as an answer (it's completely good form to do so!) so that others can find the answer that they need. – mikebader Sep 17 '21 at 13:05

1 Answers1

2

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!