This vignette shows the basics of using watlastools
. It is a work in progress.
watlastools
has two main purposes: accessing and cleaning data, and identifying residence patches from the data.
Only the latter is covered here.
knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(watlastools)
Residence patches are the end goal of the watlastools
workflow. They are a conveninent way of synthesising large amounts of tracking data into a few spatially explicit units that have a set of associated (mean) coordinates, as well as ecologically relevant coordinates such as duration.
Begin by reading in the data.
# read data and see leading lines library(data.table) data <- fread("vignette_data/413_004_revisit.csv") head(data)
Now make residence patches after inferring residence from gaps in the data.
# run the three main functions on the data # first infer residence temp_data <- wat_infer_residence(data = data, inf_patch_time_diff = 30, inf_patch_spat_diff = 100) # classify residence points temp_data <- wat_classify_points(data = temp_data, lim_res_time = 2) # make residence patches with sensible parameters patches <- wat_make_res_patch(data = temp_data, buffer_radius = 10, lim_spat_indep = 100, lim_time_indep = 30, lim_rest_indep = 30, min_fixes = 3)
Get and view the different kinds of patch data
The patch summary is a data.table and has no complex (list, sf) column types. The patches can be visualised using ggplot (or anything else).
# get patch summary patch_summary <- wat_get_patch_summary(res_patch_data = patches, which_data = "summary") # get the class of the full object and the column types class(patch_summary)
The patch points are the raw points that make up the residence patches.
# get patch points patch_points <- wat_get_patch_summary(res_patch_data = patches, which_data = "points") # get class and column type class(patch_points)
This should have the added class sf
, and the polygons column should have the type sfc_MULTIPOLYGON
.
# get patch points patch_polygons <- wat_get_patch_summary(res_patch_data = patches, which_data = "spatial") # get class and column type class(patch_polygons)
Look at patch points and summary. Polygons are constructed as x
metre buffers around patch points, and are not covered here.
The code to make this plot is in the watlas_vignette.Rmd fine in the package's vignettes folder (the source for this document).
# plotting libraries library(ggplot2) library(patchwork) # plot patch summary fig_patch_summary <- ggplot(patch_summary, aes(x_mean, y_mean))+ geom_path(col = "black", lty = 2, lwd = 0.2)+ geom_point(aes(size = duration/60, col = waterlevel_start), stroke = 2, shape = 21, fill = "black", alpha = 0.9)+ geom_text(aes(label = patch), col = "white", size = 2)+ scale_size(range = c(3,10))+ scale_colour_distiller(palette = "RdBu", direction = 1)+ scale_x_continuous(expand = expansion(mult = c(0.1)))+ scale_y_continuous(expand = expansion(mult = c(0.1)))+ coord_sf(crs = 32631)+ # annotation_scale(location = "br", width_hint = 0.1, text_cex = 1)+ theme_bw()+ theme(legend.position = "bottom", axis.text = element_blank(), axis.ticks = element_blank())+ labs(x = NULL, y = NULL, col = "waterlevel (cm NAP)", size = "residence (mins)", title = "(b) Patch summary data") # plot patch points fig_patch_points <- ggplot(patch_points, aes(x, y))+ geom_path(col = "black", lty = 2, lwd = 0.1)+ geom_point(aes(col = as.factor(patch)), shape = 21, alpha = 0.5, show.legend = F)+ scale_x_continuous(expand = expansion(mult = c(0.1)))+ scale_y_continuous(expand = expansion(mult = c(0.1)))+ scale_colour_manual(values = rep(c('red', 'blue'), (length(unique(patch_points$patch))+1) /2))+ coord_sf(crs = 32631)+ # annotation_scale(location = "br", width_hint = 0.1, text_cex = 1)+ theme_bw()+ theme(legend.position = "bottom", axis.text = element_blank(), axis.ticks = element_blank())+ labs(x = NULL, y = NULL, title = "(a) Patch point data: tag 413, tidal cycle 04")
library(patchwork) fig_patch_points / fig_patch_summary
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.