Purpose of this workshop: check, map and interpolate spatial animal movement data collected with bio-logging devices.

We will look at spatial usage, calculate kernel density and learn about projections

Note that we will go through different R packages and often packages want you to prepare the data in different ways.
Pay attention to data formats and how datasets are being manipulated.

Ways of Installing R packages

See the code below for the libraries we need for this tutorial.

Install from R-universe repository

install.packages(“aniMotum”, repos = c(“https://cloud.r-project.org”,“https://ianjonsen.r-universe.dev”), dependencies = TRUE)

Install from GitHub (same package as above)

remotes::install_github(“ianjonsen/aniMotum”)

Install from CRAN

install.packages(“track2KBA”)
install.packages(“magick”)

message("If you see masking warning these are fine (but ask me if you do not know what they mean). 
        Watch out for packages that aren't installed yet")

library(readr)
library(lubridate)
library(ggplot2)
library(ggspatial)
library(sf)
library(rnaturalearth)
library(rnaturalearthdata)
library(terra)
library(argosfilter)
library(geosphere)
library(trip)
library(tidyverse)
library(magick)
library(dplyr)
library(sp)

#packages for animal movement data
library(adehabitatHR)
library(adehabitatLT)
library(aniMotum)
library(track2KBA)

Identifying important sites for biodiversity - Masked Boobies during incubation and chick-rearing at St. Helena Island

Source:
Beal, M., et al. (2021). track2KBA: An R package for identifying important sites for biodiversity from tracking data. Methods in Ecology and Evolution, 12(12), 2372–2378. https://doi.org/10.1111/2041-210X.13713

We combine date and time in a “Date_Time column”. We create a new column where the format of the new Date_Time is changed to “posixct” format. This is an ‘R thing’ and a step you just have to do to get R to recognise this column as a date and time column. So you create a new column called ‘datetime’, based on the other column you have just created ‘Date_Time’ but with a different format (posixct): pay attention to the “grammar” (sometimes dates have / or - in between, here we have -)

data(boobies)
head(boobies)
##   track_id   date_gmt time_gmt longitude  latitude lon_colony lat_colony
## 1    69302 2012-07-22 04:17:15  -5.72638 -16.00711      -5.73     -16.01
## 2    69302 2012-07-22 04:28:57  -5.72642 -16.00716      -5.73     -16.01
## 3    69302 2012-07-21 13:04:33  -5.72646 -16.00710      -5.73     -16.01
## 4    69302 2012-07-21 13:18:24  -5.72645 -16.00714      -5.73     -16.01
## 5    69302 2012-07-21 13:40:51  -5.72627 -16.00727      -5.73     -16.01
## 6    69302 2012-07-21 14:05:43  -5.72641 -16.00708      -5.73     -16.01
# ?boobies  # for some background on the data set 

boobies$Date_Time <- paste(boobies$date_gmt, boobies$time_gmt, sep=" ")
boobies$Date_TimePosix <- as.POSIXct(boobies$Date_Time, format="%Y-%m-%d %H:%M:%S")

In order for the data to work in track2KBA functions, we can use the formatFields function to format the important data columns needed for track2KBA analysis.
These are: a DateTime field, Latitude and Longitude fields, and an ID field (i.e. individual animal, track, or trip).

dataGroup <- formatFields(
  dataGroup = boobies, 
  fieldID   = "track_id", 
  fieldDateTime  = "Date_TimePosix", 
  fieldLon  = "longitude", 
  fieldLat  = "latitude"
  )

#let's check the structure of the data
str(dataGroup)
## 'data.frame':    178006 obs. of  9 variables:
##  $ ID        : chr  "69302" "69302" "69302" "69302" ...
##  $ date_gmt  : chr  "2012-07-22" "2012-07-22" "2012-07-21" "2012-07-21" ...
##  $ time_gmt  : chr  "04:17:15" "04:28:57" "13:04:33" "13:18:24" ...
##  $ Longitude : num  -5.73 -5.73 -5.73 -5.73 -5.73 ...
##  $ Latitude  : num  -16 -16 -16 -16 -16 ...
##  $ lon_colony: num  -5.73 -5.73 -5.73 -5.73 -5.73 -5.73 -5.73 -5.73 -5.73 -5.73 ...
##  $ lat_colony: num  -16 -16 -16 -16 -16 ...
##  $ Date_Time : chr  "2012-07-22 04:17:15" "2012-07-22 04:28:57" "2012-07-21 13:04:33" "2012-07-21 13:18:24" ...
##  $ DateTime  : POSIXct, format: "2012-07-22 04:17:15" "2012-07-22 04:28:57" ...
##  - attr(*, ".internal.selfref")=<externalptr>

Boobies central-place foraging species (i.e. one which makes trips out from a centrally-located place, such as a nest in the case of a bird), you can use tripSplit to split up the data into discrete trips. In order to do this, you must identify the location(s) of the central place(s) (e.g. colony-center, or nest sites).

colony <- dataGroup %>% 
  summarise(
    Longitude = first(Longitude), 
    Latitude  = first(Latitude)
    )

#let's play with these numbers and see what happens
# see ??tripSplit() to understand the function
trips <- tripSplit(
  dataGroup  = dataGroup,
  colony     = colony,
  innerBuff  = 3,      # kilometers
  returnBuff = 10,
  duration   = 1,      # hours
  rmNonTrip  = TRUE
  )

We look at the output:

mapTrips(trips = trips, colony = colony)

We select the complete trips (there might be cases where you still want to retain all the trips) and we produce a table that summarizes the trips.

trips <- subset(trips, trips$Returns == "Yes")
sumTrips <- tripSummary(trips = trips, colony = colony)
sumTrips
## # A tibble: 213 × 10
## # Groups:   ID [40]
##    ID    tripID   n_locs departure           return              duration
##    <chr> <chr>     <dbl> <dttm>              <dttm>                 <dbl>
##  1 69302 69302_01    274 2012-07-22 07:52:11 2012-07-22 16:11:03     8.31
##  2 69302 69302_02    124 2012-07-23 12:26:22 2012-07-23 15:54:05     3.46
##  3 69302 69302_03    138 2012-07-25 08:30:53 2012-07-25 12:22:53     3.87
##  4 69305 69305_01     71 2013-08-22 13:08:15 2013-08-22 15:10:59     2.05
##  5 69306 69306_01     37 2014-01-06 16:28:42 2014-01-06 17:32:11     1.06
##  6 69306 69306_02     83 2014-01-07 14:48:24 2014-01-07 17:10:21     2.37
##  7 69306 69306_03    129 2014-01-08 14:25:11 2014-01-08 17:55:22     3.50
##  8 69306 69306_04     50 2014-01-08 18:08:32 2014-01-08 19:30:40     1.37
##  9 69306 69306_05    155 2014-01-09 14:47:04 2014-01-09 19:21:32     4.57
## 10 69307 69307_01    133 2014-01-06 14:04:22 2014-01-06 17:53:01     3.81
## # ℹ 203 more rows
## # ℹ 4 more variables: total_dist <dbl>, max_dist <dbl>, direction <dbl>,
## #   complete <chr>

We now set a projection/coordinate reference system (CRS) for our tracks.
See here useful pages:
- https://r-spatial.org/book/08-Plotting.html
- https://rstudio.github.io/cheatsheets/sf.pdf
- https://www.paulamoraga.com/book-spatial/spatial-data-in-r.html (see paragraph 2.3)

For the function “projectTracks” we can select between an azimuthal or cylindrical projection, and decide whether to center the projection on the data itself. It is important to remember that the projection choosen is specific to the dataset/research question and if we need to merge different types of datasets (tracks and environmental data for example).

azimuthal projection: all points on the map are at proportionally correct distances from the center point, and are at the correct azimuth (direction) from the center point.

tracks <- projectTracks(dataGroup = trips, projType = 'azim', custom=TRUE)
## NOTE: projection is data specific
class(tracks)
## [1] "SpatialPointsDataFrame"
## attr(,"package")
## [1] "sp"

We now try to estimate what is called a “Area Restricted Search” (ARS).
We assume that our animal uses an ARS strategy to locate prey, and we can set the scaleARS=TRUE. This uses First Passage Time analysis to identify the spatial scale at which area-restricted search is occuring, which may then be used as the smoothing parameter value.

Source:
Fauchald, P., & Tveraa, T. (2003). USING FIRST-PASSAGE TIME IN THE ANALYSIS OF AREA-RESTRICTED SEARCH AND HABITAT SELECTION. Ecology, 84(2), 282–288. https://doi.org/10.1890/0012-9658(2003)084[0282:UFPTIT]2.0.CO;2

#see the message that this code returns, and let's discuss
#plot the spatial scale at which ARS is being estimated for this dataset

hVals <- findScale(
  tracks   = tracks,
  scaleARS = TRUE,
  sumTrips = sumTrips)
## No 'res' was specified. Movement scale in the data was compared
##         to a 500-cell grid with cell size of 0.325 km squared.
## No peak found for ID(s):69309 69314 69328 69332

hVals
##   med_max_dist step_length  mag href scaleARS
## 1        22.97        0.92 3.13 5.78     29.5

We now estimate the KDE - Kernel Density Estimation.
KDE is a nonparametric technique for deriving a probability surface, known as the utilization distribution (UD), from point data. When the input are animal locations regularly spaced in time, the UD represents the probability of an animal occurring in space

Source:
Lascelles, et. al (2016). Applying global criteria to tracking data to define important areas for marine conservation. Diversity and Distributions, 22, 422–431. https://doi.org/10.1111/ddi.12411

tracks <- tracks[tracks$ColDist > 3, ] # remove trip start and end points near colony

KDE <- estSpaceUse(
  tracks = tracks, 
  scale = hVals$mag, 
  levelUD = 50, 
  polyOut = TRUE
  )
## No grid resolution ('res') was specified, or the specified resolution was
##     >99 km and therefore ignored. Space use was calculated on a 500-cell grid,
##     with cells of 0.358 square km
mapKDE(KDE = KDE$UDPolygons, colony = colony)

repr <- repAssess(
  tracks    = tracks, 
  KDE       = KDE$KDE.Surface,
  levelUD   = 50,
  iteration = 10, 
  bootTable = FALSE)
## 
## Attaching package: 'raster'
## The following object is masked from 'package:dplyr':
## 
##     select
## nls (non linear regression) successful, asymptote estimated for
##     bootstrap sample.

#explore "findSite" function and try it out!
# Site <- findSite(
#   KDE = KDE$KDE.Surface,
#   represent = repr$out,
#   levelUD = 50,
#   popSize = 500,     # 500 individual seabirds breed one the island
#   polyOut = TRUE
# )
# 
# class(Site)
# #If we specified polyOut=TRUE, then the output will be of Simple Features class, 
# #which allows us to easily take advantage of the ggplot2 plotting syntax to make an attractive map using mapSite!
# Sitemap <- mapSite(Site, colony = colony)

2. Estimate Utilisation Distribution (UD)

It is important to notice if the locations are recorded at regular time intervals. Working on datasets with locations at regular time intervals gives a more robust estimate of area usage and behaviour.

How to interpolate GPS data, useful sources:
- https://cran.r-project.org/web/packages/adehabitatLT/vignettes/adehabitatLT.pdf
- see Vignette for momentuHMM https://cran.r-project.org/web/packages/momentuHMM/index.html

For this tutorial we will be using the method implemented in adehabitat, which simply reconstructs the track via linear interpolation. Can you think of a case where linear interpolation might not be appropriate?

We start by manipulating the “trips” dataset.

#we create a dataframe, see function "as.data.frame" and how I grab the data from "trips"
boobies_tripsDF<-as.data.frame(trips@data[,c("ID","tripID","date_gmt","time_gmt","Longitude",
                                             "Latitude","Date_Time")])

# we recalculate the date time column and turn "trip ID" into a factor
boobies_tripsDF$Date_TimePosix <- as.POSIXct(boobies_tripsDF$Date_Time, format="%Y-%m-%d %H:%M:%S")
boobies_tripsDF$tripID<-as.factor(boobies_tripsDF$tripID)

# we turn it into an "ltraj" object"
raw_boobies <- as.ltraj(boobies_tripsDF[,c("Longitude","Latitude")],
                        date=boobies_tripsDF$Date_TimePosix,id=boobies_tripsDF$tripID)

is.regular(raw_boobies)
## [1] FALSE
raw_boobies
## 
## *********** List of class ltraj ***********
## 
## Type of the traject: Type II (time recorded)
## * Time zone unspecified: dates printed in user time zone *
## Irregular traject. Variable time lag between two locs
## 
## Characteristics of the bursts:
##           id    burst nb.reloc NAs          date.begin            date.end
## 1   69302_01 69302_01      274   0 2012-07-22 07:52:11 2012-07-22 16:11:03
## 2   69302_02 69302_02      124   0 2012-07-23 12:26:22 2012-07-23 15:54:05
## 3   69302_03 69302_03      138   0 2012-07-25 08:30:53 2012-07-25 12:22:53
## 4   69305_01 69305_01       71   0 2013-08-22 13:08:15 2013-08-22 15:10:59
## 5   69306_01 69306_01       37   0 2014-01-06 16:28:42 2014-01-06 17:32:11
## 6   69306_02 69306_02       83   0 2014-01-07 14:48:24 2014-01-07 17:10:21
## 7   69306_03 69306_03      129   0 2014-01-08 14:25:11 2014-01-08 17:55:22
## 8   69306_04 69306_04       50   0 2014-01-08 18:08:32 2014-01-08 19:30:40
## 9   69306_05 69306_05      155   0 2014-01-09 14:47:04 2014-01-09 19:21:32
## 10  69307_01 69307_01      133   0 2014-01-06 14:04:22 2014-01-06 17:53:01
## 11  69307_02 69307_02       88   0 2014-01-07 15:36:56 2014-01-07 18:11:57
## 12  69307_03 69307_03       74   0 2014-01-08 06:11:13 2014-01-08 08:17:03
## 13  69307_04 69307_04      134   0 2014-01-08 15:13:55 2014-01-08 19:16:00
## 14  69307_05 69307_05      142   0 2014-01-09 06:01:58 2014-01-09 10:13:29
## 15  69307_06 69307_06      128   0 2014-01-09 14:40:09 2014-01-09 18:13:48
## 16  69308_01 69308_01       84   0 2014-01-08 05:41:20 2014-01-08 08:15:04
## 17  69308_02 69308_02       69   0 2014-01-09 13:37:48 2014-01-09 15:33:45
## 18  69308_03 69308_03       39   0 2014-01-10 05:20:57 2014-01-10 06:27:08
## 19  69309_01 69309_01       48   0 2014-01-06 17:29:49 2014-01-06 18:53:07
## 20  69309_02 69309_02      106   0 2014-01-07 05:41:00 2014-01-07 08:54:53
## 21  69309_03 69309_03      102   0 2014-01-07 15:01:59 2014-01-07 18:11:52
## 22  69309_04 69309_04      107   0 2014-01-08 16:35:19 2014-01-08 19:36:56
## 23  69309_05 69309_05       53   0 2014-01-09 08:49:03 2014-01-09 10:19:15
## 24  69309_06 69309_06       82   0 2014-01-09 16:34:50 2014-01-09 18:55:46
## 25  69309_07 69309_07       93   0 2014-01-10 05:25:26 2014-01-10 08:06:59
## 26  69310_01 69310_01       44   0 2014-01-06 17:34:13 2014-01-06 18:47:03
## 27  69310_02 69310_02      143   0 2014-01-07 14:15:01 2014-01-07 18:20:08
## 28  69310_03 69310_03      153   0 2014-01-08 13:58:59 2014-01-08 18:20:38
## 29  69310_04 69310_04       59   0 2014-01-09 14:10:43 2014-01-09 15:45:34
## 30  69311_01 69311_01       87   0 2014-01-06 14:53:51 2014-01-06 17:23:25
## 31  69311_02 69311_02      114   0 2014-01-07 14:15:49 2014-01-07 17:26:15
## 32  69311_03 69311_03       43   0 2014-01-08 05:33:22 2014-01-08 06:36:55
## 33  69311_04 69311_04       43   0 2014-01-08 17:36:04 2014-01-08 18:49:56
## 34  69311_05 69311_05       62   0 2014-01-09 05:28:12 2014-01-09 07:09:50
## 35  69311_06 69311_06      138   0 2014-01-09 14:59:30 2014-01-09 18:57:38
## 36  69311_07 69311_07      110   0 2014-01-10 05:38:41 2014-01-10 08:59:31
## 37  69312_01 69312_01      106   0 2014-01-06 14:09:14 2014-01-06 17:07:47
## 38  69312_02 69312_02       79   0 2014-01-07 14:11:58 2014-01-07 16:23:44
## 39  69312_03 69312_03       95   0 2014-01-08 13:56:20 2014-01-08 16:42:03
## 40  69312_04 69312_04       93   0 2014-01-09 13:53:59 2014-01-09 16:34:23
## 41  69313_01 69313_01       65   0 2014-01-06 15:31:14 2014-01-06 17:21:48
## 42  69313_02 69313_02       75   0 2014-01-07 06:36:37 2014-01-07 08:45:41
## 43  69313_03 69313_03       48   0 2014-01-07 17:20:14 2014-01-07 18:39:47
## 44  69313_04 69313_04       62   0 2014-01-08 06:16:56 2014-01-08 08:01:37
## 45  69313_05 69313_05       71   0 2014-01-08 15:00:15 2014-01-08 17:03:16
## 46  69313_06 69313_06      171   0 2014-01-09 06:40:09 2014-01-09 11:39:44
## 47  69313_07 69313_07      105   0 2014-01-09 15:15:56 2014-01-09 18:18:11
## 48  69313_08 69313_08      110   0 2014-01-10 05:35:03 2014-01-10 08:49:03
## 49  69314_01 69314_01      100   0 2014-01-07 14:48:00 2014-01-07 17:34:41
## 50  69314_02 69314_02       91   0 2014-01-08 10:03:56 2014-01-08 12:33:41
## 51  69314_03 69314_03      169   0 2014-01-09 05:29:16 2014-01-09 10:37:24
## 52  69314_04 69314_04       67   0 2014-01-09 17:30:35 2014-01-09 19:21:54
## 53  69314_05 69314_05       49   0 2014-01-10 06:55:12 2014-01-10 08:26:57
## 54  69314_06 69314_06       72   0 2014-01-10 17:48:02 2014-01-10 19:45:42
## 55  69314_07 69314_07      206   0 2014-01-11 05:23:03 2014-01-11 11:28:15
## 56  69314_08 69314_08       69   0 2014-01-11 17:22:50 2014-01-11 19:19:33
## 57  69314_09 69314_09      163   0 2014-01-12 05:54:13 2014-01-12 10:46:12
## 58  69315_01 69315_01       47   0 2014-01-07 16:32:44 2014-01-07 17:51:11
## 59  69315_02 69315_02      103   0 2014-01-08 14:31:09 2014-01-08 17:30:51
## 60  69315_03 69315_03       81   0 2014-01-09 13:51:47 2014-01-09 16:11:04
## 61  69315_04 69315_04      173   0 2014-01-10 12:07:01 2014-01-10 17:06:03
## 62  69315_05 69315_05       33   0 2014-01-11 05:41:00 2014-01-11 06:43:50
## 63  69315_06 69315_06       92   0 2014-01-11 14:23:13 2014-01-11 16:54:28
## 64  69316_01 69316_01       56   0 2014-01-07 13:21:40 2014-01-07 14:51:04
## 65  69316_02 69316_02       95   0 2014-01-08 05:56:52 2014-01-08 08:42:47
## 66  69316_03 69316_03      105   0 2014-01-08 13:31:25 2014-01-08 16:28:13
## 67  69316_04 69316_04       65   0 2014-01-09 05:57:54 2014-01-09 07:54:58
## 68  69316_05 69316_05      188   0 2014-01-09 10:58:19 2014-01-09 16:24:51
## 69  69316_06 69316_06      149   0 2014-01-10 11:13:40 2014-01-10 15:26:32
## 70  69317_01 69317_01       57   0 2014-01-07 16:39:12 2014-01-07 18:14:10
## 71  69317_02 69317_02       71   0 2014-01-09 11:43:36 2014-01-09 13:44:27
## 72  69317_03 69317_03       36   0 2014-01-09 16:45:02 2014-01-09 17:45:45
## 73  69317_04 69317_04       73   0 2014-01-10 15:38:54 2014-01-10 17:46:39
## 74  69317_05 69317_05       51   0 2014-01-11 05:43:19 2014-01-11 07:15:21
## 75  69319_01 69319_01       49   0 2014-01-08 09:01:14 2014-01-08 10:21:27
## 76  69319_02 69319_02       47   0 2014-01-09 10:14:13 2014-01-09 11:30:22
## 77  69319_03 69319_03       76   0 2014-01-09 16:30:15 2014-01-09 18:44:40
## 78  69319_04 69319_04      155   0 2014-01-10 05:49:38 2014-01-10 10:09:37
## 79  69319_05 69319_05       59   0 2014-01-10 16:58:58 2014-01-10 18:42:36
## 80  69319_06 69319_06      126   0 2014-01-11 05:41:00 2014-01-11 09:21:02
## 81  69320_01 69320_01       62   0 2014-01-07 14:42:31 2014-01-07 16:25:18
## 82  69320_02 69320_02      132   0 2014-01-08 05:45:18 2014-01-08 09:29:01
## 83  69320_03 69320_03       55   0 2014-01-08 10:00:49 2014-01-08 11:45:39
## 84  69320_04 69320_04       56   0 2014-01-09 16:28:33 2014-01-09 18:01:32
## 85  69320_05 69320_05      118   0 2014-01-10 05:34:33 2014-01-10 08:57:06
## 86  69320_06 69320_06       61   0 2014-01-10 17:23:12 2014-01-10 19:09:00
## 87  69321_01 69321_01       58   0 2014-01-08 05:51:53 2014-01-08 07:35:03
## 88  69321_02 69321_02      136   0 2014-01-09 05:31:17 2014-01-09 09:45:50
## 89  69321_03 69321_03       72   0 2014-01-09 16:21:01 2014-01-09 18:26:53
## 90  69321_04 69321_04       95   0 2014-01-10 15:40:48 2014-01-10 18:24:03
## 91  69322_01 69322_01      134   0 2014-01-07 14:09:12 2014-01-07 18:12:07
## 92  69322_02 69322_02      170   0 2014-01-08 13:35:00 2014-01-08 18:49:34
## 93  69322_03 69322_03      121   0 2014-01-09 11:52:39 2014-01-09 15:49:30
## 94  69322_04 69322_04       79   0 2014-01-10 13:08:55 2014-01-10 15:27:42
## 95  69322_05 69322_05       71   0 2014-01-11 07:07:33 2014-01-11 09:08:16
## 96  69323_01 69323_01       71   0 2014-01-07 15:27:16 2014-01-07 17:25:20
## 97  69323_02 69323_02       53   0 2014-01-08 15:00:54 2014-01-08 16:30:27
## 98  69323_03 69323_03       56   0 2014-01-08 17:31:21 2014-01-08 19:09:58
## 99  69323_04 69323_04      122   0 2014-01-09 15:39:06 2014-01-09 19:03:34
## 100 69323_05 69323_05      190   0 2014-01-10 08:20:02 2014-01-10 13:42:40
## 101 69323_06 69323_06       50   0 2014-01-10 18:20:53 2014-01-10 19:45:57
## 102 69323_07 69323_07      113   0 2014-01-11 05:45:41 2014-01-11 08:59:53
## 103 69324_01 69324_01       49   0 2014-01-07 17:25:52 2014-01-07 18:57:42
## 104 69324_02 69324_02      153   0 2014-01-09 05:33:20 2014-01-09 09:55:11
## 105 69324_03 69324_03      393   0 2014-01-11 05:24:09 2014-01-11 16:45:57
## 106 69325_01 69325_01       53   0 2014-01-08 17:19:44 2014-01-08 18:58:29
## 107 69325_02 69325_02       37   0 2014-01-09 18:11:52 2014-01-09 19:12:18
## 108 69325_03 69325_03      110   0 2014-01-10 06:03:12 2014-01-10 09:10:56
## 109 69325_04 69325_04      123   0 2014-01-11 10:18:59 2014-01-11 13:45:40
## 110 69325_05 69325_05      122   0 2014-01-12 06:38:28 2014-01-12 10:06:46
## 111 69326_01 69326_01       65   0 2014-01-08 17:55:04 2014-01-08 19:43:59
## 112 69326_02 69326_02       98   0 2014-01-10 07:18:24 2014-01-10 10:04:27
## 113 69326_03 69326_03       80   0 2014-01-10 17:31:19 2014-01-10 19:44:00
## 114 69326_04 69326_04      191   0 2014-01-11 05:18:35 2014-01-11 10:46:43
## 115 69327_01 69327_01      148   0 2014-01-08 13:28:35 2014-01-08 17:43:25
## 116 69327_02 69327_02       95   0 2014-01-10 06:45:23 2014-01-10 09:32:27
## 117 69327_03 69327_03      189   0 2014-01-10 10:47:33 2014-01-10 16:26:28
## 118 69327_04 69327_04      183   0 2014-01-11 12:58:48 2014-01-11 18:13:11
## 119 69327_05 69327_05      168   0 2014-01-12 13:17:08 2014-01-12 18:01:55
## 120 69328_01 69328_01      113   0 2014-01-08 13:55:49 2014-01-08 17:09:39
## 121 69328_02 69328_02      122   0 2014-01-09 11:44:01 2014-01-09 14:59:54
## 122 69328_03 69328_03       47   0 2014-01-10 05:23:12 2014-01-10 06:39:51
## 123 69328_04 69328_04       76   0 2014-01-10 16:19:36 2014-01-10 18:18:26
## 124 69328_05 69328_05       59   0 2014-01-11 06:54:59 2014-01-11 08:35:49
## 125 69328_06 69328_06       94   0 2014-01-11 13:46:34 2014-01-11 16:22:05
## 126 69329_01 69329_01      142   0 2014-01-08 13:46:31 2014-01-08 17:47:14
## 127 69329_02 69329_02      140   0 2014-01-09 13:29:25 2014-01-09 17:38:41
## 128 69329_03 69329_03      182   0 2014-01-10 13:21:07 2014-01-10 18:36:04
## 129 69329_04 69329_04      308   0 2014-01-11 07:19:52 2014-01-11 16:46:56
## 130 69330_01 69330_01       61   0 2014-01-09 17:41:51 2014-01-09 19:27:02
## 131 69330_02 69330_02      166   0 2014-01-10 05:23:18 2014-01-10 10:06:53
## 132 69330_03 69330_03       73   0 2014-01-10 17:39:23 2014-01-10 19:42:23
## 133 69330_04 69330_04      112   0 2014-01-11 05:13:59 2014-01-11 08:58:57
## 134 69330_05 69330_05      246   0 2014-01-12 09:43:46 2014-01-12 16:56:25
## 135 69331_01 69331_01      193   0 2014-01-09 05:51:44 2014-01-09 11:42:26
## 136 69331_02 69331_02      217   0 2014-01-10 05:31:21 2014-01-10 12:36:16
## 137 69331_03 69331_03       92   0 2014-01-11 05:53:33 2014-01-11 08:34:34
## 138 69331_04 69331_04      191   0 2014-01-12 05:47:51 2014-01-12 11:41:21
## 139 69332_01 69332_01      113   0 2014-01-08 13:55:49 2014-01-08 17:09:39
## 140 69332_02 69332_02      122   0 2014-01-09 11:44:01 2014-01-09 14:59:54
## 141 69332_03 69332_03       47   0 2014-01-10 05:23:12 2014-01-10 06:39:51
## 142 69332_04 69332_04       76   0 2014-01-10 16:19:36 2014-01-10 18:18:26
## 143 69332_05 69332_05       59   0 2014-01-11 06:54:59 2014-01-11 08:35:49
## 144 69332_06 69332_06       94   0 2014-01-11 13:46:34 2014-01-11 16:22:05
## 145 69333_01 69333_01      106   0 2014-01-10 15:50:41 2014-01-10 18:45:38
## 146 69333_02 69333_02       40   0 2014-01-11 05:42:23 2014-01-11 06:49:42
## 147 69333_03 69333_03      172   0 2014-01-11 13:00:02 2014-01-11 17:47:11
## 148 69333_04 69333_04       57   0 2014-01-12 16:45:12 2014-01-12 18:31:27
## 149 69333_05 69333_05       71   0 2014-01-13 05:37:49 2014-01-13 07:35:04
## 150 69333_06 69333_06       62   0 2014-01-13 10:49:43 2014-01-13 12:32:15
## 151 69333_07 69333_07      161   0 2014-01-14 12:22:49 2014-01-14 16:57:56
## 152 69333_08 69333_08       63   0 2014-01-15 17:11:31 2014-01-15 18:56:10
## 153 69333_09 69333_09       52   0 2014-01-16 05:53:08 2014-01-16 07:17:37
## 154 69334_01 69334_01      109   0 2014-01-10 14:29:32 2014-01-10 17:38:57
## 155 69334_02 69334_02      218   0 2014-01-11 10:31:48 2014-01-11 16:45:48
## 156 69334_03 69334_03      166   0 2014-01-12 12:47:44 2014-01-12 17:31:30
## 157 69334_04 69334_04      201   0 2014-01-13 13:01:03 2014-01-13 18:52:27
## 158 69334_05 69334_05      196   0 2014-01-14 12:51:33 2014-01-14 18:30:58
## 159 69334_06 69334_06      110   0 2014-01-15 06:21:37 2014-01-15 09:39:37
## 160 69334_07 69334_07       93   0 2014-01-15 15:57:59 2014-01-15 18:37:11
## 161 69335_01 69335_01       79   0 2014-01-10 15:32:38 2014-01-10 17:33:24
## 162 69335_02 69335_02       60   0 2014-01-10 17:48:42 2014-01-10 19:19:20
## 163 69336_01 69336_01      231   0 2014-01-11 13:26:36 2014-01-11 17:25:18
## 164 69336_02 69336_02      207   0 2014-01-13 14:38:30 2014-01-13 18:09:15
## 165 69336_03 69336_03      345   0 2014-01-14 12:07:25 2014-01-14 18:07:35
## 166 69336_04 69336_04      219   0 2014-01-15 13:47:49 2014-01-15 18:00:09
## 167 69337_01 69337_01      101   0 2014-01-11 18:09:49 2014-01-11 19:50:51
## 168 69337_02 69337_02       89   0 2014-01-12 05:39:36 2014-01-12 07:13:32
## 169 69337_03 69337_03      606   0 2014-01-13 06:50:51 2014-01-13 18:04:16
## 170 69337_04 69337_04      121   0 2014-01-14 17:41:23 2014-01-14 19:54:52
## 171 69337_05 69337_05       70   0 2014-01-15 05:33:34 2014-01-15 06:51:03
## 172 69338_01 69338_01      109   0 2014-01-11 16:59:04 2014-01-11 18:48:37
## 173 69338_02 69338_02      247   0 2014-01-12 06:00:20 2014-01-12 10:10:20
## 174 69338_03 69338_03      167   0 2014-01-13 16:20:46 2014-01-13 19:08:14
## 175 69338_04 69338_04      588   0 2014-01-14 05:37:14 2014-01-14 15:55:45
## 176 69338_05 69338_05      118   0 2014-01-15 13:42:39 2014-01-15 15:47:55
## 177 69339_01 69339_01      124   0 2014-01-11 15:40:55 2014-01-11 17:50:02
## 178 69339_02 69339_02       80   0 2014-01-12 05:47:00 2014-01-12 07:08:29
## 179 69339_03 69339_03       59   0 2014-01-12 17:33:39 2014-01-12 18:35:07
## 180 69339_04 69339_04       99   0 2014-01-13 05:44:43 2014-01-13 07:23:17
## 181 69339_05 69339_05      109   0 2014-01-13 15:52:26 2014-01-13 17:44:53
## 182 69339_06 69339_06       92   0 2014-01-14 05:54:00 2014-01-14 07:28:07
## 183 69339_07 69339_07       86   0 2014-01-15 05:44:55 2014-01-15 07:11:26
## 184 69339_08 69339_08       89   0 2014-01-15 12:04:25 2014-01-15 13:34:06
## 185 69339_09 69339_09       84   0 2014-01-15 15:19:57 2014-01-15 16:44:07
## 186 69339_10 69339_10       93   0 2014-01-16 06:01:44 2014-01-16 07:40:50
## 187 69340_01 69340_01      439   0 2014-01-12 05:40:05 2014-01-12 13:18:55
## 188 69340_02 69340_02       91   0 2014-01-12 18:09:04 2014-01-12 19:39:52
## 189 69340_03 69340_03      259   0 2014-01-14 06:00:54 2014-01-14 10:28:18
## 190 69340_04 69340_04       89   0 2014-01-14 17:42:47 2014-01-14 19:20:43
## 191 69340_05 69340_05      312   0 2014-01-15 07:48:47 2014-01-15 13:17:36
## 192 69340_06 69340_06      133   0 2014-01-15 16:42:37 2014-01-15 19:00:05
## 193 69341_01 69341_01       66   0 2014-01-12 15:43:37 2014-01-12 16:53:38
## 194 69341_02 69341_02       60   0 2014-01-12 18:15:13 2014-01-12 19:19:14
## 195 69341_03 69341_03       96   0 2014-01-14 17:47:37 2014-01-14 19:26:58
## 196 69341_04 69341_04      120   0 2014-01-15 06:11:42 2014-01-15 08:17:26
## 197 69341_05 69341_05       61   0 2014-01-15 17:09:49 2014-01-15 18:12:32
## 198 69342_01 69342_01      127   0 2014-01-11 16:55:51 2014-01-11 19:10:11
## 199 69342_02 69342_02      121   0 2014-01-12 13:21:03 2014-01-12 15:27:48
## 200 69342_03 69342_03       76   0 2014-01-13 12:40:17 2014-01-13 14:09:45
## 201 69342_04 69342_04      233   0 2014-01-13 15:23:44 2014-01-13 19:30:41
## 202 69342_05 69342_05       98   0 2014-01-14 10:49:00 2014-01-14 12:38:51
## 203 69342_06 69342_06      220   0 2014-01-15 12:23:44 2014-01-15 16:17:06
## 204 69343_01 69343_01      333   0 2014-01-13 06:07:40 2014-01-13 12:28:00
## 205 69343_02 69343_02      239   0 2014-01-13 14:48:28 2014-01-13 19:04:59
## 206 69343_03 69343_03      704   0 2014-01-15 05:44:44 2014-01-15 18:20:35
## 207 69344_01 69344_01      234   0 2014-01-12 13:17:04 2014-01-12 17:38:48
## 208 69344_02 69344_02      166   0 2014-01-13 13:15:43 2014-01-13 16:11:42
## 209 69344_03 69344_03      192   0 2014-01-14 16:08:21 2014-01-14 19:23:40
## 210 69344_04 69344_04      164   0 2014-01-15 05:54:45 2014-01-15 08:46:19
## 211 69344_05 69344_05      129   0 2014-01-15 17:16:49 2014-01-15 19:25:33
## 212 69344_06 69344_06      528   0 2014-01-16 05:56:00 2014-01-16 15:15:59
## 213 69344_07 69344_07      209   0 2014-01-17 06:21:28 2014-01-17 10:06:29
## 
## 
##  infolocs provided. The following variables are available:
## [1] "pkey"
## Interpolation every 300 seconds (5 min), try to change this
tr <- redisltraj(raw_boobies, 300, type="time")
# adehabitat has separated each "burst" (trip ID in our case), 
# interpolated the data and then saved everything in a list
class(tr)
## [1] "ltraj" "list"
#we check that it worked, we just grab one individual
head(boobies_tripsDF[which(boobies_tripsDF$tripID=="69302_01"),])
##        ID   tripID   date_gmt time_gmt Longitude  Latitude           Date_Time
## 706 69302 69302_01 2012-07-22 07:52:11  -5.69104 -16.00650 2012-07-22 07:52:11
## 707 69302 69302_01 2012-07-22 07:53:50  -5.68132 -16.00096 2012-07-22 07:53:50
## 708 69302 69302_01 2012-07-22 07:55:29  -5.66792 -15.99466 2012-07-22 07:55:29
## 709 69302 69302_01 2012-07-22 07:57:08  -5.65702 -15.98672 2012-07-22 07:57:08
## 710 69302 69302_01 2012-07-22 07:58:46  -5.64812 -15.97719 2012-07-22 07:58:46
## 711 69302 69302_01 2012-07-22 08:00:31  -5.63664 -15.97277 2012-07-22 08:00:31
##          Date_TimePosix
## 706 2012-07-22 07:52:11
## 707 2012-07-22 07:53:50
## 708 2012-07-22 07:55:29
## 709 2012-07-22 07:57:08
## 710 2012-07-22 07:58:46
## 711 2012-07-22 08:00:31
head(tr[[1]]) #trip column is gone
##           x         y                date         dx         dy       dist  dt
## 1 -5.691040 -16.00650 2012-07-22 07:52:11 0.03429245 0.02007173 0.03973470 300
## 2 -5.656748 -15.98643 2012-07-22 07:57:11 0.03055517 0.02061065 0.03685671 300
## 3 -5.626192 -15.96582 2012-07-22 08:02:11 0.02936107 0.01333715 0.03224829 300
## 4 -5.596831 -15.95248 2012-07-22 08:07:11 0.02954187 0.01114579 0.03157453 300
## 5 -5.567289 -15.94133 2012-07-22 08:12:11 0.02828203 0.01739615 0.03320391 300
## 6 -5.539007 -15.92394 2012-07-22 08:17:11 0.02938288 0.01684852 0.03387073 300
##           R2n abs.angle   rel.angle
## 1 0.000000000 0.5295485          NA
## 2 0.001578847 0.5934327  0.06388426
## 3 0.005860270 0.4263793 -0.16705338
## 4 0.011793387 0.3607751 -0.06560422
## 5 0.019560721 0.5514454  0.19067023
## 6 0.029930307 0.5206406 -0.03080473
is.regular(tr)
## [1] TRUE
#let's see how the interpolated tracks look like
plot.ltraj(tr)

#we take back our tripID
ID<-burst(tr)
#and we attach it back to each level of our list
tr <- mapply(cbind, tr, "tripID"=ID, SIMPLIFY=F)

#we take everything out from the list and save it as a data.frame
boobies_tripsDF_Reg<-do.call(rbind.data.frame, tr)
colnames(boobies_tripsDF_Reg)[1:2]<-c("Longitude","Latitude")

#we select the columns we are interested in:
boobies_tripsDF_Reg<-boobies_tripsDF_Reg[,c("tripID", "Longitude","Latitude","date","dist","rel.angle")]
boobies_tripsDF_Reg$Date_TimePosix <- as.POSIXct(boobies_tripsDF_Reg$date, format="%Y-%m-%d %H:%M:%S")
#we take the track id back
ListTrips<-str_split(boobies_tripsDF_Reg$tripID, "_")
boobies_tripsDF_Reg$track_id<-as.factor(sapply(ListTrips,"[[",1))

We can now go back to the function “formatFields” and what we have done with the R package track2KBA and recalculate ARS and KDE. How do results change ??

dataGroupReg <- formatFields(
  dataGroup = boobies_tripsDF_Reg, 
  fieldID   = "track_id", 
  fieldDateTime  = "Date_TimePosix", 
  fieldLon  = "Longitude", 
  fieldLat  = "Latitude"
  )

tripsReg <- tripSplit(
  dataGroup  = dataGroupReg,
  colony     = colony,
  innerBuff  = 3,      # kilometers
  returnBuff = 10,
  duration   = 1,      # hours
  rmNonTrip  = TRUE
  )

tripsReg <- subset(tripsReg, tripsReg$Returns == "Yes")
mapTrips(trips = tripsReg, colony = colony)

tracksReg <- projectTracks(dataGroup = tripsReg, projType = 'azim', custom=TRUE)
sumTripsReg <- tripSummary(trips = tripsReg, colony = colony)

hVals <- findScale(
  tracks   = tracksReg,
  scaleARS = TRUE,
  sumTrips = sumTrips)

KDEReg <- estSpaceUse(
  tracks = tracksReg, 
  scale = hVals$mag, 
  levelUD = 50, 
  polyOut = TRUE
  )

mapKDE(KDE = KDEReg$UDPolygons, colony = colony)

We now prepare for the kernel density, core area (50%) and home range (90-95%)

# Run the kernel home range analysis - don't be concerned if you get a warning message.
# kernel analysis runs on UTM projections and "Spatial Points Data Frame"

boobies_HR<-SpatialPointsDataFrame(coords=cbind(boobies_tripsDF_Reg$Longitude, boobies_tripsDF_Reg$Latitude),
                               data=boobies_tripsDF_Reg[,c("Longitude","Latitude")],
                               proj4string = CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"))

boobies_HR <- spTransform(boobies_HR,CRS("+proj=utm +zone=30 +south +datum=WGS84 +units=m +no_defs"))

boobies.HR_kud<-kernelUD(boobies_HR, h="href")
## Warning in kernelUD(boobies_HR, h = "href"): xy should contain only one column (the id of the animals)
## id ignored
#Extract the 90% kernel:
boobies.kud.90<-getverticeshr(boobies.HR_kud,90, unout="km2")
boobies.kud.90
## Object of class "SpatialPolygonsDataFrame" (package sp):
## 
## Number of SpatialPolygons:  1
## 
## Variables measured:
##                  id     area
## homerange homerange 9460.387
#Extract the 50% kernel
boobies.kud.50<-getverticeshr(boobies.HR_kud,50, unout="km2")
boobies.kud.50
## Object of class "SpatialPolygonsDataFrame" (package sp):
## 
## Number of SpatialPolygons:  1
## 
## Variables measured:
##                  id     area
## homerange homerange 955.2574

We now merge the kernel objects and plot them in one map

# turn the kernels in sf objects for plotting
boobies.kud.50_sf<-st_as_sf(boobies.kud.50)
#Projection transformation
boobies.kud.50_sf <- st_transform(boobies.kud.50_sf, crs = "+proj=longlat +datum=WGS84")
boobies.kud.50_sf$id<-"HR 50"

boobies.kud.90_sf<-st_as_sf(boobies.kud.90)
#Projection transformation
boobies.kud.90_sf <- st_transform(boobies.kud.90_sf, crs = "+proj=longlat +datum=WGS84")
boobies.kud.90_sf$id<-"HR 90"

#merge the kernels in one sf object
single_sf_boobies <- dplyr::bind_rows(list(boobies.kud.90_sf,boobies.kud.50_sf))

#Load the world map (this won’t plot it, but you can see it’s loaded in the top right hand window)
theme_set(theme_bw())
world <- ne_countries(scale = "medium", returnclass = "sf")
class(world)
## [1] "sf"         "data.frame"
# we build the map
sf::sf_use_s2(FALSE)
myMap<-ggplot() +
  geom_sf(data = world)+
  geom_point(data=boobies_tripsDF_Reg, mapping=aes(x=Longitude, y=Latitude),colour = "deepskyblue4",alpha=0.2)+
    geom_sf(data=single_sf_boobies, mapping=aes(fill=id),alpha=0.4)+
  scale_fill_manual(name="kernel - HR",values=c("HR 90" = "gray60", "HR 50" = "gray10"))+
  coord_sf(xlim=c(-7,-3),ylim=c(-17,-14))+
  xlab(expression(paste("Longitude (", degree,"W)"))) +
  ylab(expression(paste("Latitude (", degree,"S)")))+

 #here our code for adding the scale bar, 
  #see how i call a function for a specific package (ggspatial::)
  #this is because sometimes similar packages "mask" each-other functions

       ggspatial::annotation_scale(
       location = "tr", #tr means "top right", try tl!
       bar_cols = c("grey60", "white"),
       text_family = "ArcherPro Book") +
       ggspatial::annotation_north_arrow(
       location = "tr", which_north = "true",
       pad_x = unit(0.4, "in"), pad_y = unit(0.4, "in"), #this is where in the plot you want the north arrow, try different numbers
       style = ggspatial::north_arrow_nautical(
      fill = c("grey40", "white"),
      line_col = "grey20",
      text_family = "ArcherPro Book"
          )
        )
myMap

3. Work on Argos (satellite data) - the case of Southern Elephant Seals

Load and inspect the dataset, inspect and discuss the data with me or the demonstrator. column “tag_id” is our animal id, so it would be best to set it as a factor column “lc” is stating the location error associated to the Argos data.

data(sese)
head(sese)
## # A tibble: 6 × 5
##   id           date                lc      lon   lat
##   <chr>        <dttm>              <fct> <dbl> <dbl>
## 1 ct109-085-14 2015-02-03 00:11:02 B      70.4 -49.9
## 2 ct109-085-14 2015-02-03 13:26:37 B      71   -50.2
## 3 ct109-085-14 2015-02-03 21:53:15 B      71.3 -50.4
## 4 ct109-085-14 2015-02-04 04:05:35 A      71.6 -50.4
## 5 ct109-085-14 2015-02-04 17:12:42 B      72.0 -50.5
## 6 ct109-085-14 2015-02-05 02:05:44 B      72.4 -50.5
str(sese)
## tibble [4,163 × 5] (S3: tbl_df/tbl/data.frame)
##  $ id  : chr [1:4163] "ct109-085-14" "ct109-085-14" "ct109-085-14" "ct109-085-14" ...
##  $ date: POSIXct[1:4163], format: "2015-02-03 00:11:02" "2015-02-03 13:26:37" ...
##  $ lc  : Factor w/ 7 levels "3","2","1","0",..: 6 6 6 5 6 6 5 6 6 6 ...
##  $ lon : num [1:4163] 70.5 71 71.3 71.6 72 ...
##  $ lat : num [1:4163] -49.9 -50.2 -50.4 -50.4 -50.5 ...
unique(sese$lc)
## [1] B A 1 3 0 2 Z
## Levels: 3 2 1 0 A B Z
summary(sese)
##       id                 date                     lc            lon        
##  Length:4163        Min.   :2015-01-26 10:13:39   3:  17   Min.   : 26.91  
##  Class :character   1st Qu.:2015-04-18 23:11:46   2:  51   1st Qu.: 45.31  
##  Mode  :character   Median :2015-08-03 23:59:01   1: 151   Median : 74.37  
##                     Mean   :2016-02-04 04:54:22   0: 324   Mean   : 68.65  
##                     3rd Qu.:2017-03-30 06:18:51   A:1343   3rd Qu.: 83.46  
##                     Max.   :2017-06-14 04:43:22   B:2276   Max.   :123.18  
##                                                   Z:   1                   
##       lat        
##  Min.   :-69.14  
##  1st Qu.:-63.81  
##  Median :-59.13  
##  Mean   :-58.33  
##  3rd Qu.:-52.39  
##  Max.   :-46.96  
## 

Is the time interval between the locations regular?

No, we will be using the R package AniMotum to interpolate the data

We will now use aniMotum to interpolate these tracks

sese$date <- as.POSIXct(sese$date, format="%d/%m/%Y %H:%M")
sese$lc<-as.factor(sese$lc)


sese <- format_data(sese, date = "date", coord = c("lon", "lat"))
sese
## # A tibble: 4,163 × 10
##    id        date                lc      lon   lat  smaj  smin   eor  x.sd  y.sd
##    <chr>     <dttm>              <fct> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
##  1 ct109-93… 2015-01-26 10:13:39 B      67.1 -50.7    NA    NA    NA    NA    NA
##  2 ct109-93… 2015-01-26 12:17:17 A      67.5 -50.6    NA    NA    NA    NA    NA
##  3 ct109-93… 2015-01-26 16:02:13 B      67.7 -50.6    NA    NA    NA    NA    NA
##  4 ct109-93… 2015-01-26 20:00:53 A      67.0 -50.7    NA    NA    NA    NA    NA
##  5 ct109-93… 2015-01-26 23:15:39 B      66.7 -50.8    NA    NA    NA    NA    NA
##  6 ct109-93… 2015-01-27 03:36:54 B      66.6 -50.8    NA    NA    NA    NA    NA
##  7 ct109-93… 2015-01-27 12:17:40 A      66.2 -50.9    NA    NA    NA    NA    NA
##  8 ct109-93… 2015-01-27 16:39:18 B      66.0 -51.1    NA    NA    NA    NA    NA
##  9 ct109-93… 2015-01-27 19:03:16 B      65.9 -51.2    NA    NA    NA    NA    NA
## 10 ct109-93… 2015-01-28 01:04:04 B      65.6 -51.3    NA    NA    NA    NA    NA
## # ℹ 4,153 more rows
# go and see what the function fit_ssm does
fit <- fit_ssm(sese,
               model = "crw",
               time.step = 24,
               control = ssm_control(verbose = 0))
#we plot the predictions from the crw
plot(fit, what = "p", type=2, pages = 1, ncol = 2)

#we plot the tracks on a map
aniMotum::map(fit,
    what = "predicted",
    crs = "+proj=stere +lon_0=68 +units=km +datum=WGS84")
## using map scale: 10

let’s try to run the same code as above and calculate kernels for the ses dataset

## grab predicted locations in projected form (UTM)
predicted_Locations_sese <- as_Spatial(grab(fit, what = "predicted", as_sf = TRUE))
predicted_Locations_sese[1:5,]
## class       : SpatialPointsDataFrame 
## features    : 5 
## extent      : 7842.458, 8241.61, -6497.22, -6401.444  (xmin, xmax, ymin, ymax)
## crs         : +proj=merc +lon_0=0 +k=1 +x_0=0 +y_0=0 +datum=WGS84 +units=km +no_defs 
## variables   : 10
## names       :           id,       date,                   u,                 v,                 u.se,                 v.se,                 x.se,                 y.se,                     s, s.se 
## min values  : ct109-085-14, 1422921600, 2.7388081620337e-10, -2.75503084411621, 9.99999999976125e-06, 9.99999999972904e-06, 9.99999999999276e-06, 9.99999999998164e-06, 7.95862072520621e-315,   NA 
## max values  : ct109-085-14, 1423267200,    4.99784721885472,  1.21141365510112,    0.634038682498776,    0.548971619274693,     5.63048042961706,      3.9071288572019,       5.5520939172256,   NA
#Run the kernel home range analysis - don't be concerned if you get a warning message.
# kernel analysis runs on UTM projections
sese.kud<-kernelUD(predicted_Locations_sese, h="href")
## Warning in kernelUD(predicted_Locations_sese, h = "href"): xy should contain only one column (the id of the animals)
## id ignored
#Extract the 90% kernel:
sese.kud.90<-getverticeshr(sese.kud,90, unout="km2")
sese.kud.90
## Object of class "SpatialPolygonsDataFrame" (package sp):
## 
## Number of SpatialPolygons:  1
## 
## Variables measured:
##                  id     area
## homerange homerange 50.15317
#Extract the 50% kernel
sese.kud.50<-getverticeshr(sese.kud,50, unout="km2")
sese.kud.50
## Object of class "SpatialPolygonsDataFrame" (package sp):
## 
## Number of SpatialPolygons:  1
## 
## Variables measured:
##                  id     area
## homerange homerange 16.50194
# turn the kernels in sf objects for plotting
sese.kud.50_sf<-st_as_sf(sese.kud.50)
#Projection transformation
sese.kud.50_sf <- st_transform(sese.kud.50_sf, crs = "+proj=longlat +datum=WGS84")
sese.kud.50_sf$id<-"HR 50"

sese.kud.90_sf<-st_as_sf(sese.kud.90)
#Projection transformation
sese.kud.90_sf <- st_transform(sese.kud.90_sf, crs = "+proj=longlat +datum=WGS84")
sese.kud.90_sf$id<-"HR 90"

#merge the kernels in one sf object
single_sf_sese <- dplyr::bind_rows(list(sese.kud.90_sf,sese.kud.50_sf))

#Load the world map (this won’t plot it, but you can see it’s loaded in the top right hand window)
theme_set(theme_bw())
world <- ne_countries(scale = "medium", returnclass = "sf")
class(world)
## [1] "sf"         "data.frame"
# we build the map
sf::sf_use_s2(FALSE)
myMap<-ggplot() +
  geom_sf(data = world)+
  geom_point(data=sese, mapping=aes(x=lon, y=lat),colour = "deepskyblue4",alpha=0.2)+
    geom_sf(data=single_sf_sese, mapping=aes(fill=id),alpha=0.4)+
  scale_fill_manual(name="kernel - HR",values=c("HR 90" = "gray60", "HR 50" = "gray10"))+
  coord_sf(xlim=c(20,120),ylim=c(-85,-35))+
  xlab(expression(paste("Longitude (", degree,"W)"))) +
  ylab(expression(paste("Latitude (", degree,"S)")))+
       ggspatial::annotation_scale(
       location = "tr", #tr means "top right", try tl!
       bar_cols = c("grey60", "white"),
       text_family = "ArcherPro Book") +
       ggspatial::annotation_north_arrow(
       location = "tr", which_north = "true",
       pad_x = unit(0.4, "in"), pad_y = unit(0.4, "in"), #this is where in the plot you want the north arrow, try different numbers
       style = ggspatial::north_arrow_nautical(
      fill = c("grey40", "white"),
      line_col = "grey20",
      text_family = "ArcherPro Book"
          )
        )
myMap
## Scale on map varies by more than 10%, scale bar may be inaccurate

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.