In the next tasks we will look for “meet” patterns in our wild boar data. To simplify this, we will only use a subset of our wild boar data: The individuals Rosa and Sabi for the timespan 01.04.2015 - 15.04.2015. Use the dataset wildschwein_BE_2056.csv (on moodle). Import the csv as a data.frame and filter it with the aforementioned criteria. You do not need to convert the data.frame to an sf object.
Have a look at your dataset. You will notice that samples are taken at every full hour, quarter past, half past and quarter to. The sampling time is usually off by a couple of seconds.
To compare Rosa and Sabi’s locations, we first need to match the two animals temporally. For that we can use a join, but need identical time stamps to serve as a join key. We therefore need to slightly adjust our time stamps to a common, concurrent interval.
The task is therfore to round the minutes of DatetimeUTC to a multiple of 15 (00, 15, 30,45) and store the values in a new column1. You can use the lubridate function round_date() for this.
Task 4: Measuring distance at concurrent locations
To measure the distance between concurrent locations, we need to follow the following steps.
Split the wildschwein_filter object into one data.frame per animal
Join these datasets by the new Datetime column created in the last task. The joined observations are temporally close.
In the joined dataset, calculate Euclidean distances between concurrent observations and store the values in a new column
Use a reasonable threshold on distance to determine if the animals are also spatially close enough to constitute a meet (we use 100 meters). Store this Boolean information (TRUE/FALSE) in a new column
# Splitting the dataset by animalboar_split <- boar |>group_split(TierID)# Renaming columns for mergingboar_1 <- boar_split[[1]] |>rename(E1 = E, N1 = N) |>select(TierID, TierName, Datetime_round, E1, N1)boar_2 <- boar_split[[2]] |>rename(E2 = E, N2 = N) |>select(TierID, TierName, Datetime_round, E2, N2)# Merging datasets by rounded datetimeboar_joined <-full_join(boar_1, boar_2, by ="Datetime_round") |>drop_na()# Calculating Euclidean distanceboar_joined <- boar_joined |>mutate(distance =sqrt((E2 - E1)^2+ (N2 - N1)^2),meet = distance <=100) # 100m threshold
Task 5: Visualize data
# Visualiseboar_meet <- boar_joined |>filter(meet == T)ggplot() +# Points for boar_1 with color and alphageom_point(data = boar_1, aes(x = E1, y = N1, color ="Sabi"), alpha =0.5) +geom_point(data = boar_2, aes(x = E2, y = N2, color ="Rosa"), alpha =0.5) +geom_point(data = boar_meet, aes(x = E1, y = N1, color ="Boar Meeting (not via Teams)"), alpha =0.8, shape =10, stroke =1) +# Customize the legend labels and colorsscale_color_manual(values =c("Sabi"="pink", "Rosa"="orange", "Boar Meeting (not via Teams)"="brown")) +labs(x ="E", y ="N", color ="Legend") +theme_minimal()