Type: | Package |
Title: | Animation of Multiple Trajectories with Uncertainty |
Version: | 0.10.5 |
Date: | 2025-3-1 |
Maintainer: | Henry Scharf <hscharf@arizona.edu> |
Description: | Animation of observed trajectories using spline-based interpolation (see for example, Buderman, F. E., Hooten, M. B., Ivan, J. S. and Shenk, T. M. (2016), <doi:10.1111/2041-210X.12465> "A functional model for characterizing long-distance movement behaviour". Methods Ecol Evol). Intended to be used exploratory data analysis, and perhaps for preparation of presentations. |
License: | GPL-3 |
RoxygenNote: | 7.3.2 |
Depends: | R (≥ 3.5.0) |
Imports: | animation, RColorBrewer, sf, crawl, mgcv, grDevices, ggmap, dplyr, ellipse, ggplot2, igraph, lubridate, magrittr, mvtnorm, stringr, tidyr, tidyselect |
Suggests: | knitr, rmarkdown, terra, testthat |
VignetteBuilder: | knitr |
LazyData: | true |
Encoding: | UTF-8 |
NeedsCompilation: | no |
Packaged: | 2025-03-01 21:10:14 UTC; hscharf |
Author: | Henry Scharf [aut, cre], Kristine Dinh [aut], Rosales Hugo [aut], Rivera Angelica [aut] |
Repository: | CRAN |
Date/Publication: | 2025-03-02 03:50:02 UTC |
animate paths
Description
Animates telemetry data for the purposed of EDA using smoothing splines to interpolate the observed locations. The animations are particularly useful when examining multiple simultaneous trajectories. The output of the call to animate_paths()
should bring up a browser window that shows the animation. Additionally, the images generated in images/
(or else the value set for imgdir
) may be used with ffmpeg, latex, or other presentation software that can build animations directly from a sequence of images.
Usage
animate_paths(
paths,
coord = c("x", "y"),
Time.name = "time",
background = NULL,
bg.axes = TRUE,
bg.misc = NULL,
bg.opts = NULL,
blur.size = 8,
covariate = NULL,
covariate.colors = c("black", "white"),
covariate.legend.loc = "bottomright",
covariate.thresh = NULL,
crawl.mu.color = "black",
crawl.plot.type = "point.tail",
date.col = "black",
delta.t = NULL,
dev.opts = list(),
dimmed = NULL,
ID.name = NULL,
interpolation_type = "gam",
interval = 1/12,
legend.loc = "topright",
main = NULL,
max_refit_attempts = 10,
method = "html",
n.frames = NULL,
network = NULL,
network.colors = NULL,
network.thresh = 0.5,
network.times = NULL,
network.ring.trans = 1,
network.ring.wt = 3,
network.segment.trans = 0.5,
network.segment.wt = 3,
override = FALSE,
par.opts = list(),
paths.proj = "+proj=longlat",
paths.tranform.crs = "+proj=aea",
plot.date = TRUE,
pt.alpha = 0.4,
pt.cex = 1,
pt.colors = NULL,
pt.wd = 1,
res = 1.5,
return.paths = FALSE,
s_args = NULL,
simulation = FALSE,
simulation.iter = 12,
tail.alpha = 0.6,
tail.colors = "gray87",
tail.length = 5,
tail.wd = 1,
theme_map = NULL,
times = NULL,
uncertainty.level = NA,
uncertainty.type = 1,
whole.path = FALSE,
xlim = NULL,
ylim = NULL,
verbose = FALSE,
...
)
Arguments
paths |
Either a |
coord |
A character vector of length 2 giving the names of the longitude/easting and latitude/northing columns in the |
Time.name |
The name of the columns in |
background |
Three possibilities: (1) A single background image over which animation will be overlayed, or a SpatRaster objects with one layers corresponding to each frame. (2) A list with values |
bg.axes |
logical: should animation place axis labels when using a background image (default is |
bg.misc |
Character string which will be executed as |
bg.opts |
Options passed to |
blur.size |
a integer of the size for blur points; default is 8 |
covariate |
The name of the column in |
covariate.colors |
vector of colors which will be used in their given order to make a color ramp (see |
covariate.legend.loc |
either the location of the covariate legend, or |
covariate.thresh |
if changed from its default value of |
crawl.mu.color |
color for the main predictions for crawl interpolation; default is black |
crawl.plot.type |
a character string of what type of the plot you wish to generate when |
date.col |
default is |
delta.t |
The gap in time between each frame in the animation. Specify one of |
dev.opts |
Options passed to |
dimmed |
Numeric vector of individuals to "dim" in the animation. Order corresponds to the order of the ID.name variable, or order of paths list. |
ID.name |
The name of the column in |
interpolation_type |
a character string of the type of interpolation. Default is "gam" for a generalized addictive model. Use "crawl" to interpolate using |
interval |
Seconds per frame in animation. Default is 1/12 (or 12 frames per second). |
legend.loc |
passed to first argument of |
main |
Title for each frame. |
max_refit_attempts |
an integer of number of resampling when the fit for crawl failed to run; default is 10 |
method |
either |
n.frames |
The number of frames used to animate the complete time domain of the data. |
network |
Array of dimensions (# individuals, # individuals, |
network.colors |
A symmetric matrix of dimension |
network.thresh |
Network structure is summarized in the animation in a binary way, regardless of whether or not the |
network.times |
Numeric vector. If network time grid doesn't match |
network.ring.trans |
transparency of network segments (default is 1) |
network.ring.wt |
thickness of network rings (default is 3) |
network.segment.trans |
transparency of network segments (default is 0.5) |
network.segment.wt |
thickness of network segments (default is 3) |
override |
Logical variable toggling where or not to override warnings about how long the animation procedure will take. |
par.opts |
Options passed to |
paths.proj |
PROJ.4 string corresponding to the projection of the data. Default is "+proj=longlat". |
paths.tranform.crs |
a PROJ.4 string of coordinate projection transformation based on the animals' location; default is "+proj=aea +lat_1=30 +lat_2=70". |
plot.date |
Logical variable toggling date text at the time center of the animation. |
pt.alpha |
alpha value for the points |
pt.cex |
A numeric value giving the character expansion (size) of the points for each individual. Default is 1. |
pt.colors |
A vector of colors to be used for each individual in the animation. Default values come from Color Brewer palettes. When a network is provided, this is ignored and individuals are all colored black. If |
pt.wd |
size of the points; default is 1 |
res |
Resolution of images in animation. Increase this for higher quality (and larger) images. |
return.paths |
logical. Default is |
s_args |
Default is |
simulation |
logical. Generate simulation predictions to have multiple projects for the animal paths; default is |
simulation.iter |
an integer of how many paths the crawl model will generate; default is 5. |
tail.alpha |
alpha value for the tails |
tail.colors |
default is |
tail.length |
Length of the tail trailing each individual. |
tail.wd |
Thickness of tail trailing behind each individual. Default is 1. |
theme_map |
plot theme for |
times |
If all paths are already synchronous, another option for passing the data is to define |
uncertainty.level |
value in (0, 1) corresponding to |
uncertainty.type |
State what type of uncertainty plot 1 is default for tails more than 1 is amount of predicted trajectories for each unique individual and blurs for blur plot |
whole.path |
logical. If |
xlim |
Boundaries for plotting. If left undefined, the range of the data will be used. |
ylim |
Boundaries for plotting. If left undefined, the range of the data will be used. |
verbose |
logical; |
... |
other arguments to be passed to |
Value
video file, possibly a directory containing the individual images, or interpolated paths.
Examples
##
vultures$POSIX <- as.POSIXct(vultures$timestamp, tz = "UTC")
vultures_paths <- vultures[vultures$POSIX > as.POSIXct("2009-03-01", origin = "1970-01-01") &
vultures$POSIX < as.POSIXct("2009-05-01", origin = "1970-01-01"), ]
animate_paths(
paths = vultures_paths,
delta.t = "week",
coord = c("location.long", "location.lat"),
Time.name = "POSIX",
ID.name = "individual.local.identifier"
)
## Not run:
background <- list(
center = c(-90, 10),
zoom = 3,
maptype = "satellite"
)
library(ggmap)
library(RColorBrewer)
COVARIATE <- cos(as.numeric(vultures_paths$timestamp) /
diff(range(as.numeric(vultures_paths$timestamp))) * 4 * pi)
animate_paths(
paths = cbind(vultures_paths, COVARIATE),
delta.t = "week",
coord = c("location.long", "location.lat"),
Time.name = "POSIX", covariate = "COVARIATE",
covariate.colors = brewer.pal(n = 9, "RdYlGn"),
ID.name = "individual.local.identifier",
background = background
)
# animation using crawl interpolation
animate_paths(
paths = vultures_paths,
delta.t = "week",
coord = c("location.long", "location.lat"),
Time.name = "POSIX",
ID.name = "individual.local.identifier",
interpolation_type = "crawl"
)
## End(Not run)
# Run to remove files generated by this function
system("rm -r js; rm -r css; rm -r images; rm index.html")
Animation Expression
Description
Animation Expression
Usage
animation_expression(
bg,
bg.axes,
bg.misc,
bg.opts,
blur.size,
cliques,
color_covariate_function,
coord,
covariate,
covariate.factors,
covariate.interp,
covariate.legend.loc,
covariate.name,
covariate.range,
covariate.thresh,
covariate.ticks,
crawl.mu.color,
crawl.plot.type,
cur.time,
date.col,
delta.t,
dev.opts,
dimmed,
ID_names,
interpolation_type,
interval,
legend.loc,
main,
method,
n.frames,
network,
network.interp,
network.ring.trans,
network.ring.wt,
network.segment.trans,
network.thresh,
network.segment.wt,
par.opts,
paths,
paths.interp,
plot.date,
pt.alpha,
pt.cex,
pt.colors,
pt.wd,
res,
scale,
simulation,
simulation.iter,
tail.alpha,
tail.colors,
tail.length,
tail.wd,
theme_map,
time.grid,
Time.name,
uncertainty.level,
uncertainty.type,
whole.path,
xlim,
ylim,
...
)
Arguments
bg |
a list object for the ggmap background if background object is supplied |
bg.axes |
logical: should animation place axis labels when using a background image (default is |
bg.misc |
Character string which will be executed as |
bg.opts |
Options passed to |
blur.size |
a integer of the size for blur points; default is 8 |
cliques |
A list of colors for network projections |
color_covariate_function |
a function to generate color for covariate interpolation |
coord |
A character vector of length 2 giving the names of the longitude/easting and latitude/northing columns in the |
covariate |
The name of the column in |
covariate.factors |
factor levels for covariate interpolation |
covariate.interp |
interpolation for covariate projections |
covariate.legend.loc |
either the location of the covariate legend, or |
covariate.name |
name of covariate interpolation |
covariate.range |
the range of covariate interpolation |
covariate.thresh |
if changed from its default value of |
covariate.ticks |
|
crawl.mu.color |
color for the main predictions for crawl interpolation; default is black |
crawl.plot.type |
a character string of what type of the plot you wish to generate when |
cur.time |
start time of animation |
date.col |
default is |
delta.t |
The gap in time between each frame in the animation. Specify one of |
dev.opts |
Options passed to |
dimmed |
Numeric vector of individuals to "dim" in the animation. Order corresponds to the order of the ID.name variable, or order of paths list. |
ID_names |
a list of names for each animal in the data |
interpolation_type |
a character string of the type of interpolation. Default is "gam" for a generalized addictive model. Input "crawl" to interpolate using |
interval |
Seconds per frame in animation. Default is 1/12 (or 12 frames per second). |
legend.loc |
passed to first argument of |
main |
Title for each frame. SOON: support for changing titles to allow for, say, dates. |
method |
either |
n.frames |
The number of frames used to animate the complete time domain of the data. |
network |
Array of dimensions (# individuals, # individuals, |
network.interp |
interpolated network of dimension |
network.ring.trans |
transparency of network segments (default is 1) |
network.ring.wt |
thickness of network rings (default is 3) |
network.segment.trans |
|
network.thresh |
|
network.segment.wt |
thickness of network segments (default is 3) |
par.opts |
Options passed to |
paths |
A list of all paths from each animals stored in a |
paths.interp |
a path animation object that contains all predicted and simulated paths for all animals |
plot.date |
Logical variable toggling date text at the time center of the animation. |
pt.alpha |
alpha value for the points |
pt.cex |
A numeric value giving the character expansion (size) of the points for each individual. Default is 1. |
pt.colors |
A vector of colors to be used for each individual in the animation. Default values come from Color Brewer palettes. When a network is provided, this is ignored and individuals are all colored black. If |
pt.wd |
size of the points; default is 1 |
res |
Resolution of images in animation. Increase this for higher quality (and larger) images. |
scale |
|
simulation |
logical. Generate simulation predictions to have multiple projects for the animal paths |
simulation.iter |
an integer of how many paths the crawl model will generate |
tail.alpha |
alpha value for the tails |
tail.colors |
default is "gray87". Can be single color or vector of colors. |
tail.length |
Length of the tail trailing each individual. |
tail.wd |
Thickness of tail trailing behind each individual. Default is 1. |
theme_map |
plot theme for ggplot, default is NULL |
time.grid |
A vector of time interval. |
Time.name |
The name of the columns in |
uncertainty.level |
value in (0, 1) corresponding to |
uncertainty.type |
State what type of uncertainty plot 1 is default for tails more than 1 is amount of predicted trajectories for each unique individual and blurs for blur plot |
whole.path |
logical. If |
xlim |
Boundaries for plotting. If left undefined, the range of the data will be used. |
ylim |
Boundaries for plotting. If left undefined, the range of the data will be used. |
... |
other arguments to be passed to |
Value
animation for different methods and different interpolation types
blur ellipses function
Description
blur ellipses function
Usage
blur_point(
x,
levels = seq(0.001, 1 - 0.1, l = 15),
alpha_mult,
col = "black",
center
)
Arguments
x |
An object. In the default method the parameter x should be a correlation between -1 and 1 or a square positive definite matrix at least 2x2 in size. It will be treated as the correlation or covariance of a multivariate normal distribution. |
levels |
contour levels |
alpha_mult |
multiplier on transparency level |
col |
default is black |
center |
two-vector giving center of ellipse |
Check overwrite
Description
Check overwrite
Usage
check_overwrite(method, return.paths, ...)
Arguments
method |
passed from animate_paths() |
return.paths |
passed from animate_paths() |
... |
passed from animate_paths(); used to check for user-specified value for img.name |
Value
NULL, unless there is risk of over-writting and the user interrupts animation (FALSE
)
Synchronous interpolation of covariate using either GAM (same as paths) or piece-wise constant if covariate is a factor
Description
Synchronous interpolation of covariate using either GAM (same as paths) or piece-wise constant if covariate is a factor
Usage
covariate_interp(paths, covariate = NULL, Time.name, time.grid, s_args)
Arguments
paths |
lists of data.frames containing positions, times, and covariate for each individual |
covariate |
character string giving name of covariate variable in data.frames |
Time.name |
character string giving name of time variable in data.frames |
time.grid |
grid of possible times to use for interpolation (individuals will only be interpolated to times within the range of observation times) |
s_args |
arguments to |
Value
list of interpolated covariate by individual
Single and Multiple Realizations Using crawl Package
Description
Single and Multiple Realizations Using crawl Package
Usage
crawl_interpolation(
coord,
delta.t,
ID_names,
max_refit_attempts,
n.indiv,
paths,
paths.proj,
paths.tranform.crs,
simulation,
simulation.iter,
time.grid,
Time.name
)
Arguments
coord |
A character vector of length 2 giving the names of the longitude/easting and latitude/northing columns in the |
delta.t |
The gap in time between each frame in the animation. Specify one of |
ID_names |
a list of names for each animal in the data |
max_refit_attempts |
an integer of number of attempts per individual to fit crawl model |
n.indiv |
an integer of the total number of unique animals in the data |
paths |
A list of all paths from each animals stored in a |
paths.proj |
PROJ.4 string corresponding to the projection of the data |
paths.tranform.crs |
a character string of coordinate projection transformation based on the animals' location. |
simulation |
logical. Generate simulation predictions to have multiple projects for the animal paths |
simulation.iter |
an integer of how many paths the crawl model will generate |
time.grid |
grid for synchronized interpolations |
Time.name |
The name of the columns in |
Value
interpolation values from crawl package
GAM interpolation using mgcv:gam()
.
Description
GAM interpolation using mgcv:gam()
.
Usage
gam_interp(
formula = NULL,
y,
time,
pred_times,
se.fit = T,
s_args = NULL,
uncertainty.type,
verbose = F
)
Arguments
formula |
optionally specify formula for |
y |
observations |
time |
times for observations |
pred_times |
prediction times |
se.fit |
logical default is |
s_args |
Arguments to |
uncertainty.type |
State what type of uncertainty plot 1 is default for tails more than 1 is amount of predicted trajectories for each unique individual and blurs for blur plot |
verbose |
logical; |
Value
interpolated values
Figure out scale and centering of google map by transforming reported lat long bounding box back to web mercator
Description
Figure out scale and centering of google map by transforming reported lat long bounding box back to web mercator
Usage
get_googlemap_min_scale(map)
Arguments
map |
|
Value
scale (factor by which web mercator has been shrunk) and min (leftmost, bottom most coordinate of rectangle)
get_network_colors() Finds all maximal cliques in the network at each time point and tries to assign them a useful coloring
Description
get_network_colors() Finds all maximal cliques in the network at each time point and tries to assign them a useful coloring
Usage
get_network_colors(binary.network, network.color.options = NULL)
Arguments
binary.network |
a 3D array giving the time-varying adjecency matrix of a dynamic network. |
network.color.options |
vector of colors |
Value
a list of two elements: a list of the maximal cliques at each time, and c list with colors for each clique at each time
adjust center + scale for google map plotting
Description
adjust center + scale for google map plotting
Usage
googlemap_proj(x, map)
Arguments
x |
|
map |
|
Value
two-column matrix of locations from x
projected to match map
Synchronous interpolation of network using piece-wise constant interpolation
Description
Synchronous interpolation of network using piece-wise constant interpolation
Usage
network_interp(network = NULL, network.times, time.grid)
Arguments
network |
array of network observations of dimension ( |
network.times |
vector of times at which network observations are made |
time.grid |
times at which network will be interpolated |
Value
array of dimension n.indiv, n.indiv, length(time.grid))
Get good alpha_mult
Description
Get good alpha_mult
Usage
new_alpha(sd1, sd2)
Arguments
sd1 |
standard deviation of longitude |
sd2 |
standard deviation of latitude |
Value
scalar value to be used for alpha_mult in blur_point()
Synchronous GAM interpolation of all paths
Description
Synchronous GAM interpolation of all paths
Usage
paths_gam_interp(
paths,
coord,
Time.name,
time.grid,
s_args = NULL,
uncertainty.type,
verbose = F
)
Arguments
paths |
lists of data.frames containing positions, times, and covariate for each individual |
coord |
two-vector of character strings giving names of x and y coordinates in data.frames |
Time.name |
character string giving name of time variable in data.frames |
time.grid |
grid of possible times to use for interpolation (individuals will only be interpolated to times within the range of observation times) |
s_args |
List of arguments to |
uncertainty.type |
State what type of uncertainty plot 1 is default for tails more than 1 is amount of predicted trajectories for each unique individual and blurs for blur plot |
verbose |
logical; |
Value
list of interpolated paths by individual
Plot animation path interpolation
Description
This is mainly intended as a way to check that the interpolations used in the animation are working as expected.
Usage
## S3 method for class 'paths_animation'
plot(x, ..., i = 1, level = 0.05, type = "path", ylim_x = NULL, ylim_y = NULL)
Arguments
x |
|
... |
additional arguments passed to |
i |
index of individual to plot (corresponds to index in |
level |
confidence level for error bands. |
type |
either |
ylim_x |
y-axis limits for marginal plots (x, easting, etc.) |
ylim_y |
y-axis limits for marginal plots (y, northing, etc.) |
Examples
vultures$POSIX <- as.POSIXct(vultures$timestamp, tz = "UTC")
vultures_paths <- vultures[vultures$POSIX > as.POSIXct("2009-03-22", origin = "1970-01-01") &
vultures$POSIX < as.POSIXct("2009-04-05", origin = "1970-01-01"), ]
interpolated_paths <-
animate_paths(
paths = vultures_paths,
delta.t = 3600 * 6,
coord = c("location.long", "location.lat"),
Time.name = "POSIX",
ID.name = "individual.local.identifier",
s_args = rep(list(list(k = 10)), 6),
return.paths = TRUE
)
plot(interpolated_paths, i = 2)
GPS locations of turkey vultures.
Description
A dataset containing a subset of the locations of turkey vultures (2003–2006), with time stamps, from:
Usage
vultures
Format
A data frame with 215719 rows and 11 variables:
- timestamp
time of observation
- location.long
logitude
- location.lat
latitude
- individual.local.identifier
identifier for each individual
...
Details
Dodge S, Bohrer G, Bildstein K, Davidson SC, Weinzierl R, Mechard MJ, Barber D, Kays R, Brandes D, Han J (2014) Environmental drivers of variability in the movement ecology of turkey vultures (Cathartes aura) in North and South America. Philosophical Transactions of the Royal Society B 20130195. doi:10.1098/rstb.2013.0195
Bildstein K, Barber D, Bechard MJ (2014) Data from: Environmental drivers of variability in the movement ecology of turkey vultures (Cathartes aura) in North and South America. Movebank Data Repository. doi:10.5441/001/1.46ft1k05
Source
doi:10.5441/001/1.46ft1k05 Bildstein K, Barber D, Bechard MJ (2014) Data from: Environmental drivers of variability in the movement ecology of turkey vultures (Cathartes aura) in North and South America. Movebank Data Repository.
GPS locations of three species of whales.
Description
A dataset containing locations of whales, with time stamps, from:
Usage
whales
Format
A data frame with 4303 rows and 4 variables:
- timestamp
time of observation
- location.long
logitude
- location.lat
latitude
- individual.local.identifier
identifier for each individual
...
Details
Irvine LM, Winsor MH, Follett TM, Mate BR, Palacios DM (2020) An at-sea assessment of Argos location accuracy for three species of large whales, and the effect of deep-diving behavior on location error. Animal Biotelemetry 8:20.
Irvine LM, Follett TM, Winsor MH, Mate BR, Palacios DM (2020) Data from: Study "Blue and fin whales Southern California 2014-2015 - Argos data". Movebank Data Repository. doi:10.5441/001/1.98f5r6d0
Source
doi:10.5441/001/1.98f5r6d0 Irvine LM, Follett TM, Winsor MH, Mate BR, Palacios DM (2020) Data from: Study "Blue and fin whales Southern California 2014-2015 - Argos data". Movebank Data Repository.