Title: | Modern Classes for Tracking and Movement Data |
---|---|
Description: | Modern classes for tracking and movement data, building on 'sf' spatial infrastructure, and early theoretical work from Turchin (1998, ISBN: 9780878938476), and Calenge et al. (2009) <doi:10.1016/j.ecoinf.2008.10.002>. Tracking data are series of locations with at least 2-dimensional spatial coordinates (x,y), a time index (t), and individual identification (id) of the object being monitored; movement data are made of trajectories, i.e. the line representation of the path, composed by steps (the straight-line segments connecting successive locations). 'sftrack' is designed to handle movement of both living organisms and inanimate objects. |
Authors: | Matthew Boone [aut] |
Maintainer: | Mathieu Basille <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.5.4 |
Built: | 2025-03-09 04:26:57 UTC |
Source: | https://github.com/mablab/sftrack |
The active group is the combination of group names to group the data sets. The active_group acts essentially like a paste(names_of_groups, sep = '_') grouping variable.
active_group(x)
active_group(x)
x |
a c_grouping |
#' data("raccoon") raccoon$timestamp <- as.POSIXct(raccoon$timestamp, "EST") burstz <- list(id = raccoon$animal_id, month = as.POSIXlt(raccoon$timestamp)$mon) mb1 <- make_c_grouping(x = burstz, active_group = c("id", "month")) # see the current active burst active_group(mb1) # change the active burst active_group(mb1) <- "id" # Using a full data set my_track <- as_sftrack(raccoon, time = "timestamp", error = NA, coords = c("longitude", "latitude"), group = burstz ) summary(my_track) # change active group active_group(my_track$sft_group) <- "id" summary(my_track)
#' data("raccoon") raccoon$timestamp <- as.POSIXct(raccoon$timestamp, "EST") burstz <- list(id = raccoon$animal_id, month = as.POSIXlt(raccoon$timestamp)$mon) mb1 <- make_c_grouping(x = burstz, active_group = c("id", "month")) # see the current active burst active_group(mb1) # change the active burst active_group(mb1) <- "id" # Using a full data set my_track <- as_sftrack(raccoon, time = "timestamp", error = NA, coords = c("longitude", "latitude"), group = burstz ) summary(my_track) # change active group active_group(my_track$sft_group) <- "id" summary(my_track)
Set new active group
active_group(x) <- value ## S3 replacement method for class 'sftrack' active_group(x) <- value ## S3 replacement method for class 'sftraj' active_group(x) <- value ## S3 replacement method for class 'c_grouping' active_group(x) <- value
active_group(x) <- value ## S3 replacement method for class 'sftrack' active_group(x) <- value ## S3 replacement method for class 'sftraj' active_group(x) <- value ## S3 replacement method for class 'c_grouping' active_group(x) <- value
x |
sftrack/sftraj/c_grouping/s_group object |
value |
character vector of the grouping names to make active |
This function converts x,y,z data into an sftrack object with a sf_geometry column of sf_POINTS. Creates a 'grouping' column to group movement data and sets dedicated time and error columns.
Raw data inputted in two ways: vector or data.frame. 'Vector' inputs gives the argument as a vector where length = nrow(data). 'Data.frame' inputs gives the arguments as the column name of 'data' where the input can be found. Either input is allowed on any given argument.
Some options are global and required regardless
as_sftrack(data = data.frame(), ...) ## S3 method for class 'data.frame' as_sftrack( data = data.frame(), ..., coords = c("x", "y"), group = "id", active_group = NA, time = "time", error = NA, crs = NA, zeroNA = FALSE, group_name = "sft_group", timestamp_name = "sft_timestamp", error_name = "sft_error", overwrite_names = FALSE ) ## S3 method for class 'sftraj' as_sftrack(data, ...) ## S3 method for class 'ltraj' as_sftrack(data, ...) ## S3 method for class 'sf' as_sftrack( data, ..., coords, group, active_group = NA, time, error = NA, group_name = "sft_group", timestamp_name = "sft_timestamp", error_name = "sft_error", overwrite_names = FALSE )
as_sftrack(data = data.frame(), ...) ## S3 method for class 'data.frame' as_sftrack( data = data.frame(), ..., coords = c("x", "y"), group = "id", active_group = NA, time = "time", error = NA, crs = NA, zeroNA = FALSE, group_name = "sft_group", timestamp_name = "sft_timestamp", error_name = "sft_error", overwrite_names = FALSE ) ## S3 method for class 'sftraj' as_sftrack(data, ...) ## S3 method for class 'ltraj' as_sftrack(data, ...) ## S3 method for class 'sf' as_sftrack( data, ..., coords, group, active_group = NA, time, error = NA, group_name = "sft_group", timestamp_name = "sft_timestamp", error_name = "sft_error", overwrite_names = FALSE )
data |
a data.frame of the movement data, if supplied all data.frame inputs, than is optional |
... |
extra information to be passed on to as_sftrack |
coords |
a character vector describing where the x,y,z coordinates are located in 'data' or a list with x,y,z (optional) vectors |
group |
a list of named vectors describing multiple grouping variables or a character vector naming the other grouping columns in 'data'. |
active_group |
a character vector of the burst names to be 'active' to group data by for analysis |
time |
a vector of time information, can be either POSIX or an integer or a character string naming the column in 'data' where the time information is located |
error |
(optional) a vector of error information for the movement dataa character string naming the column in 'data' where the error information is located |
crs |
Coordinate reference system to be assigned; object of class 'crs'. Defaults to NA |
zeroNA |
logical whether to convert 0s in spatial data into NAs. Defaults to FALSE. |
group_name |
(optional) new column name for grouping data |
timestamp_name |
(optional) new column name for time data |
error_name |
(optional) new column name for error data |
overwrite_names |
T/F Whether to overwrite data if a group/time/error column name is supplied but already in data |
Convert objects into sftrack objects.
#' data("raccoon") raccoon$timestamp <- as.POSIXct(raccoon$timestamp, "EST") burstz <- list(id = raccoon$animal_id, month = as.POSIXlt(raccoon$timestamp)$mon) # Input is a data.frame my_track <- as_sftrack(raccoon, group = burstz, time = "timestamp", error = NA, coords = c("longitude", "latitude") ) # Input is a ltraj library("adehabitatLT") ltraj_df <- as.ltraj( xy = raccoon[, c("longitude", "latitude")], date = as.POSIXct(raccoon$timestamp), id = raccoon$animal_id, typeII = TRUE, infolocs = raccoon[, 1:6] ) my_sftrack <- as_sftrack(ltraj_df) head(my_sftrack) # Input is a sf object library("sf") df1 <- raccoon[!is.na(raccoon$latitude), ] sf_df <- st_as_sf(df1, coords = c("longitude", "latitude")) new_sftrack <- as_sftrack(sf_df, group = c(id = "animal_id"), time = "timestamp") head(new_sftrack) # Input is an sftraj object my_traj <- as_sftraj(raccoon, time = "timestamp", error = NA, coords = c("longitude", "latitude"), group = burstz ) new_track <- as_sftrack(my_traj) head(new_track) ###################### # Builder
#' data("raccoon") raccoon$timestamp <- as.POSIXct(raccoon$timestamp, "EST") burstz <- list(id = raccoon$animal_id, month = as.POSIXlt(raccoon$timestamp)$mon) # Input is a data.frame my_track <- as_sftrack(raccoon, group = burstz, time = "timestamp", error = NA, coords = c("longitude", "latitude") ) # Input is a ltraj library("adehabitatLT") ltraj_df <- as.ltraj( xy = raccoon[, c("longitude", "latitude")], date = as.POSIXct(raccoon$timestamp), id = raccoon$animal_id, typeII = TRUE, infolocs = raccoon[, 1:6] ) my_sftrack <- as_sftrack(ltraj_df) head(my_sftrack) # Input is a sf object library("sf") df1 <- raccoon[!is.na(raccoon$latitude), ] sf_df <- st_as_sf(df1, coords = c("longitude", "latitude")) new_sftrack <- as_sftrack(sf_df, group = c(id = "animal_id"), time = "timestamp") head(new_sftrack) # Input is an sftraj object my_traj <- as_sftraj(raccoon, time = "timestamp", error = NA, coords = c("longitude", "latitude"), group = burstz ) new_track <- as_sftrack(my_traj) head(new_track) ###################### # Builder
This function converts x,y,z data into an sftrack object with a sf_geometry column of sf_POINTS. Creates a 'grouping' column to group movement data and sets dedicated time and error columns.
Raw data inputted in two ways: vector or data.frame. 'Vector' inputs gives the argument as a vector where length = nrow(data). 'Data.frame' inputs gives the arguments as the column name of 'data' where the input can be found. Either input is allowed on any given argument.
Some options are global and required regardless
as_sftraj(data = data.frame(), ...) ## S3 method for class 'data.frame' as_sftraj( data = data.frame(), ..., coords = c("x", "y"), group = "id", active_group = NA, time = "time", error = NA, crs = NA, zeroNA = FALSE, group_name = "sft_group", timestamp_name = "sft_timestamp", error_name = "sft_error", overwrite_names = FALSE ) ## S3 method for class 'sftrack' as_sftraj(data, ...) ## S3 method for class 'sf' as_sftraj( data, ..., coords, group, active_group = NA, time, error = NA, group_name = "sft_group", timestamp_name = "sft_timestamp", error_name = "sft_error", overwrite_names = FALSE ) ## S3 method for class 'ltraj' as_sftraj(data, ...)
as_sftraj(data = data.frame(), ...) ## S3 method for class 'data.frame' as_sftraj( data = data.frame(), ..., coords = c("x", "y"), group = "id", active_group = NA, time = "time", error = NA, crs = NA, zeroNA = FALSE, group_name = "sft_group", timestamp_name = "sft_timestamp", error_name = "sft_error", overwrite_names = FALSE ) ## S3 method for class 'sftrack' as_sftraj(data, ...) ## S3 method for class 'sf' as_sftraj( data, ..., coords, group, active_group = NA, time, error = NA, group_name = "sft_group", timestamp_name = "sft_timestamp", error_name = "sft_error", overwrite_names = FALSE ) ## S3 method for class 'ltraj' as_sftraj(data, ...)
data |
a data.frame of the movement data, if supplied all data.frame inputs, than is optional |
... |
extra information to be passed on to as_sftrack |
coords |
a character vector describing where the x,y,z coordinates are located in 'data' or a list with x,y,z (optional) vectors |
group |
a list of named vectors describing multiple grouping variables or a character vector naming the other grouping columns in 'data'. |
active_group |
a character vector of the burst names to be 'active' to group data by for analysis |
time |
a vector of time information, can be either POSIX or an integer or a character string naming the column in 'data' where the time information is located |
error |
(optional) a vector of error information for the movement dataa character string naming the column in 'data' where the error information is located |
crs |
Coordinate reference system to be assigned; object of class 'crs'. Defaults to NA |
zeroNA |
logical whether to convert 0s in spatial data into NAs. Defaults to FALSE. |
group_name |
(optional) new column name for grouping data |
timestamp_name |
(optional) new column name for time data |
error_name |
(optional) new column name for error data |
overwrite_names |
T/F Whether to overwrite data if a group/time/error column name is supplied but already in data |
Convert objects into sftrack objects.
#' data("raccoon") raccoon$timestamp <- as.POSIXct(raccoon$timestamp, "EST") burstz <- list(id = raccoon$animal_id, month = as.POSIXlt(raccoon$timestamp)$mon) # Input is a data.frame my_track <- as_sftraj(raccoon, group = burstz, time = "timestamp", error = NA, coords = c("longitude", "latitude") ) # Input is a ltraj library("adehabitatLT") ltraj_df <- as.ltraj( xy = raccoon[, c("longitude", "latitude")], date = as.POSIXct(raccoon$timestamp), id = raccoon$animal_id, typeII = TRUE, infolocs = raccoon[, 1:6] ) my_sftrack <- as_sftraj(ltraj_df) head(my_sftrack) # Input is a sf object library("sf") df1 <- raccoon[!is.na(raccoon$latitude), ] sf_df <- st_as_sf(df1, coords = c("longitude", "latitude")) new_sftrack <- as_sftrack(sf_df, group = c(id = "animal_id"), time = "timestamp") head(new_sftrack) # Input is an sftrack object my_track <- as_sftrack(raccoon, time = "timestamp", error = NA, coords = c("longitude", "latitude"), group = burstz ) new_traj <- as_sftraj(my_track) head(new_traj) ######################
#' data("raccoon") raccoon$timestamp <- as.POSIXct(raccoon$timestamp, "EST") burstz <- list(id = raccoon$animal_id, month = as.POSIXlt(raccoon$timestamp)$mon) # Input is a data.frame my_track <- as_sftraj(raccoon, group = burstz, time = "timestamp", error = NA, coords = c("longitude", "latitude") ) # Input is a ltraj library("adehabitatLT") ltraj_df <- as.ltraj( xy = raccoon[, c("longitude", "latitude")], date = as.POSIXct(raccoon$timestamp), id = raccoon$animal_id, typeII = TRUE, infolocs = raccoon[, 1:6] ) my_sftrack <- as_sftraj(ltraj_df) head(my_sftrack) # Input is a sf object library("sf") df1 <- raccoon[!is.na(raccoon$latitude), ] sf_df <- st_as_sf(df1, coords = c("longitude", "latitude")) new_sftrack <- as_sftrack(sf_df, group = c(id = "animal_id"), time = "timestamp") head(new_sftrack) # Input is an sftrack object my_track <- as_sftrack(raccoon, time = "timestamp", error = NA, coords = c("longitude", "latitude"), group = burstz ) new_traj <- as_sftraj(my_track) head(new_traj) ######################
Calculate a new sort index for groups
calc_sort_index(x, active_group = NA)
calc_sort_index(x, active_group = NA)
x |
group or sftrack object |
active_group |
(optional), a new active group. If not included, defaults to the active group (if a c_grouping) or the group names |
Check there is a grouping id present
check_group_id(x)
check_group_id(x)
x |
a c_grouping |
Are group names equivalent for each s_group?
check_group_names(x)
check_group_names(x)
x |
a c_grouping |
Check if coordinates contain NAs in some columns but not others
check_NA_coords(xyz)
check_NA_coords(xyz)
xyz |
a data.frame of xy or xyz coordinates |
Check there are no NAs in burst
check_NA_group(x)
check_NA_group(x)
x |
a c_grouping |
Check if a set of column names are found in a data frame and return an error if not
check_names_exist(data, names)
check_names_exist(data, names)
data |
a data.frame to check names against |
names |
the inputted column names |
Checks if grouping is ordered by time and then outputs the correct order
check_ordered(group, time_data, return = TRUE)
check_ordered(group, time_data, return = TRUE)
group |
a c_grouping |
time_data |
a vector of time |
return |
T/F return the new order or just run check? |
Check if time is regular for each burst and returns logical for each burst
check_t_regular(x)
check_t_regular(x)
x |
an sftrack/sftraj object |
Check if time is integer or posix
check_time(time)
check_time(time)
time |
a vector of time |
check that time is unique
dup_timestamp(x, time)
dup_timestamp(x, time)
x |
An sftrack/sftraj object or a multi_burst |
time |
vector of time, not required if given a sftrack object. |
fix 0's to NAs in latitude and longitude
fix_zero(xyz)
fix_zero(xyz)
xyz |
a data.frame of xy or xyz coordinates |
returns a data.frame with 0s replaced with NAs
This function can be added to ggplot() to plot an sftrack and sftraj Function does not yet work with ggplot grammer so you must but data= in this function
geom_sftrack(mapping, data, ...) ## S3 method for class 'sftrack' geom_sftrack(mapping = ggplot2::aes(), data = NULL, ...) ## S3 method for class 'sftraj' geom_sftrack(mapping = ggplot2::aes(), data = NULL, ..., step_mode = FALSE)
geom_sftrack(mapping, data, ...) ## S3 method for class 'sftrack' geom_sftrack(mapping = ggplot2::aes(), data = NULL, ...) ## S3 method for class 'sftraj' geom_sftrack(mapping = ggplot2::aes(), data = NULL, ..., step_mode = FALSE)
mapping |
mapping aesthetics for ggplot. |
data |
the sftraj or sftrack object. |
... |
arguments to passed to ggplot |
step_mode |
TRUE/FALSE, whether to plot in step_mode, See details |
step mode refers to considering the trajectory as individual 'steps', in the case of plot this means it will plot each line & point individually. This approach is much slower to plot when n(steps)>10,000. The alternative method is to merge the steps into a multilinestring of continuous lines. This is much faster to plot.
#' require("ggplot2") data("raccoon") raccoon$timestamp <- as.POSIXct(raccoon$timestamp, "EST") burstz <- c(id = "animal_id") # sftraj will as well for the most part, however as its a more complex # structure to speed up plotting. my_sftraj <- as_sftraj(raccoon, time = "timestamp", coords = c("longitude", "latitude"), group = burstz ) ggplot() + geom_sftrack(data = my_sftraj)
#' require("ggplot2") data("raccoon") raccoon$timestamp <- as.POSIXct(raccoon$timestamp, "EST") burstz <- c(id = "animal_id") # sftraj will as well for the most part, however as its a more complex # structure to speed up plotting. my_sftraj <- as_sftraj(raccoon, time = "timestamp", coords = c("longitude", "latitude"), group = burstz ) ggplot() + geom_sftrack(data = my_sftraj)
Shows grouping labels created from the s_group and the c_grouping
group_labels(x) ## S3 method for class 'sftrack' group_labels(x) ## S3 method for class 'sftraj' group_labels(x) ## S3 method for class 'c_grouping' group_labels(x)
group_labels(x) ## S3 method for class 'sftrack' group_labels(x) ## S3 method for class 'sftraj' group_labels(x) ## S3 method for class 'c_grouping' group_labels(x)
x |
a sftrack or grouping object |
Display the levels of the sort index
group_names(x) ## S3 method for class 'c_grouping' group_names(x) ## S3 method for class 'sftraj' group_names(x) ## S3 method for class 'sftrack' group_names(x)
group_names(x) ## S3 method for class 'c_grouping' group_names(x) ## S3 method for class 'sftraj' group_names(x) ## S3 method for class 'sftrack' group_names(x)
x |
sftrack/sftraj/c_grouping/s_group object |
This class describes grouping variables for movement data. The grouping object is composed of a list with named vectors. One of which must be 'id', this is the id of subject being monitored (commonly animal id in movement data) Can be any number of groups after that.
make_s_group(x) make_c_grouping(x = NULL, active_group = NULL) ## S3 method for class 's_group' c(...) ## S3 method for class 'c_grouping' c(..., recursive = FALSE)
make_s_group(x) make_c_grouping(x = NULL, active_group = NULL) ## S3 method for class 's_group' c(...) ## S3 method for class 'c_grouping' c(..., recursive = FALSE)
x |
a list containing named grouping variables, one item must be named 'id'. ex: list(id = 1, month = 'may'). For a c_grouping: A list of s_groups or a list of equal length named vectors which will be combined to create a c_grouping. ex: list(x = 1st_vector, y = 2nd_vector) |
active_group |
a vector of the names of the groups to be considered 'active'. |
... |
objects to be pasted together into a c_grouping |
recursive |
ignored |
A grouping is a list of possible categories to group the data. The 'active group' of these is the current grouping variables to be considered for analysis. The 'active group' can be any combination of the categories in a burst, and can change with the use of 'active_group()'.
An 's_group' is a single row group. It is a 1xn dimensional list with any length(n) > 1. Atleast one of the groups must be named 'id' which is the subjects id.
A 'c_grouping' is a collection of 's_groups's, it is a data.frame with dimensions of 1xnrow(data). One c_grouping has one 'active group' which describes the set of names in each s_group to group the data. When you change the 'active group', calculations and plots change accordingly to the new grouping levels.
You can create bursts with make_s_group and make_c_grouping.
# Make a single group #' make_s_group(x = list(id = "CJ11", month = 3, height = 10)) # Make a c_grouping data("raccoon") raccoon$timestamp <- as.POSIXct(raccoon$timestamp, "EST") burstz <- list(id = raccoon$animal_id, month = as.POSIXlt(raccoon$timestamp)$mon) mb1 <- make_c_grouping(x = burstz, active_group = c("id", "month")) str(mb1) # Make a multi_burst from many ind_bursts a <- make_s_group(list(id = 1, year = 2020)) b <- make_s_group(list(id = 1, year = 2020)) c <- make_s_group(list(id = 2, year = 2020)) c(a, b, c)
# Make a single group #' make_s_group(x = list(id = "CJ11", month = 3, height = 10)) # Make a c_grouping data("raccoon") raccoon$timestamp <- as.POSIXct(raccoon$timestamp, "EST") burstz <- list(id = raccoon$animal_id, month = as.POSIXlt(raccoon$timestamp)$mon) mb1 <- make_c_grouping(x = burstz, active_group = c("id", "month")) str(mb1) # Make a multi_burst from many ind_bursts a <- make_s_group(list(id = 1, year = 2020)) b <- make_s_group(list(id = 1, year = 2020)) c <- make_s_group(list(id = 2, year = 2020)) c(a, b, c)
A step is a movement from one point to the next, with an sftraj object this manifests as a linestring. If, however, one of these two points is missing, the sftraj is created as a geometery collection of two points, the beginning and the end point, where one of the steps is NA. This function checks a trajectory geometry if its a linestring and returns a vector of T/F.
is_linestring(x)
is_linestring(x)
x |
an sftraj object |
This calculates step geometries as individual line segments based on the active_group
make_step_geom(group, time_data, geometry)
make_step_geom(group, time_data, geometry)
group |
a c_grouping object |
time_data |
time vector |
geometry |
the geometery data from either sf or sf_track. Must be an sf geometry class |
#' library("sf") geom <- st_as_sf(data.frame( x = c(1, 2, 2, 5), y = c(0, 1, 5, 7) ), coords = c("x", "y")) burst <- list(id = rep(1, 4)) time <- 1:4 cg <- make_c_grouping(burst) make_step_geom( group = cg, geometry = geom$geometry, time_data = time )
#' library("sf") geom <- st_as_sf(data.frame( x = c(1, 2, 2, 5), y = c(0, 1, 5, 7) ), coords = c("x", "y")) burst <- list(id = rep(1, 4)) time <- 1:4 cg <- make_c_grouping(burst) make_step_geom( group = cg, geometry = geom$geometry, time_data = time )
This function returns a sf object grouped by each burst with a geometry column of multilinestrings for each grouping
merge_traj(x)
merge_traj(x)
x |
an sftraj object |
Define an sftrack
new_sftrack(data, group_col, sf_col, time_col, error_col = NA)
new_sftrack(data, group_col, sf_col, time_col, error_col = NA)
data |
data.frame with multi_burst column, geometry column, time_col (integer/POSIXct), and error column (optional) |
group_col |
column name of grouping info in 'data' |
sf_col |
column name of geometry info in 'data' |
time_col |
column name of time info in 'data' |
error_col |
column name of error info in 'data' |
Define an sftraj
new_sftraj(data, group_col, sf_col, time_col, error_col = NA)
new_sftraj(data, group_col, sf_col, time_col, error_col = NA)
data |
data.frame with multi_burst column, geometry column, time_col (integer/POSIXct), and error column (optional) |
group_col |
column name of multi_burst in 'data' |
sf_col |
column name of geometry in 'data' |
time_col |
column name of time in 'data' |
error_col |
column name of error in 'data' |
Methods for plotting sftrack/sftraj
Methods for plotting sftrack/sftraj
## S3 method for class 'sftrack' plot(x, y, key.pos, key.width, ...) ## S3 method for class 'sftraj' plot(x, y, key.pos, key.width, ..., step_mode)
## S3 method for class 'sftrack' plot(x, y, key.pos, key.width, ...) ## S3 method for class 'sftraj' plot(x, y, key.pos, key.width, ..., step_mode)
x |
'sftrack' or 'sftraj' object |
y |
ignored |
key.pos |
Integer; side to plot a color key: 1 bottom, 2 left,
3 top, 4 right; set to NULL to omit key, or -1 to select
automatically (defaults to 4; see |
key.width |
Amount of space reserved for the key, including
labels (see |
... |
Further arguments passed to 'plot.sf'. Among others, arguments for the key are set differently in 'sftrack' to allow for longer labels by default (but can be nevertheless adjusted). |
step_mode |
Logical; whether to plot in step mode, see details, defaults to TRUE, unless there are more than 10,000 steps. |
Step mode refers to considering the trajectory as individual 'steps', in the case of plot this means it will plot each line & point individually. This approach is much slower to plot with large objects, and is thus turned off when n(steps)>10,000. The alternative, much faster method is to merge the steps into a multilinestring as continuous lines.
## Prepare an 'sftrack' object: data("raccoon") raccoon$timestamp <- as.POSIXct(raccoon$timestamp, "EST") burstz <- c(id = "animal_id") my_sftrack <- as_sftrack(raccoon, time = "timestamp", coords = c("longitude", "latitude"), group = burstz ) ## Plotting with sftrack is just like sf. `...` will accept most ## arguments as 'plot.sf': plot(my_sftrack, axes = TRUE, lwd = 5, cex = 5, bgc = "gray50") ## sftraj will as well for the most part; however it is a more complex ## structure that combines points and steps (in step mode): my_sftraj <- as_sftraj(raccoon, time = "timestamp", coords = c("longitude", "latitude"), group = burstz ) plot(my_sftraj, lwd = 5, cex = 5, bgc = "gray50", graticule = TRUE)
## Prepare an 'sftrack' object: data("raccoon") raccoon$timestamp <- as.POSIXct(raccoon$timestamp, "EST") burstz <- c(id = "animal_id") my_sftrack <- as_sftrack(raccoon, time = "timestamp", coords = c("longitude", "latitude"), group = burstz ) ## Plotting with sftrack is just like sf. `...` will accept most ## arguments as 'plot.sf': plot(my_sftrack, axes = TRUE, lwd = 5, cex = 5, bgc = "gray50") ## sftraj will as well for the most part; however it is a more complex ## structure that combines points and steps (in step mode): my_sftraj <- as_sftraj(raccoon, time = "timestamp", coords = c("longitude", "latitude"), group = burstz ) plot(my_sftraj, lwd = 5, cex = 5, bgc = "gray50", graticule = TRUE)
Print methods for sftrack
## S3 method for class 'sftrack' print(x, n_row, n_col, ...)
## S3 method for class 'sftrack' print(x, n_row, n_col, ...)
x |
sftraj object |
n_row |
Integer of number of rows to display. Defaults to global option default if non supplied |
n_col |
Integer of number of columns to display + required sftrack columns (burst, geometry, time, and error). Defaults to global option default if non supplied |
... |
other arguments passed onto print |
Print methods for sftraj
## S3 method for class 'sftraj' print(x, n_row, n_col, ...)
## S3 method for class 'sftraj' print(x, n_row, n_col, ...)
x |
sftraj object |
n_row |
Integer of number of rows to display. Defaults to global option default if non supplied |
n_col |
Integer of number of columns to display + required sftrack columns (burst, geometry, time, and error). Defaults to global option default if non supplied |
... |
other arguments passed onto print |
A dataset of two raccoons collared with GPS collars for one month in January 2019 in Tree Tops Park, Broward County, Florida, US.
raccoon
raccoon
A data frame with 445 rows and 10 variables:
ID of individual. TTP: tree tops park, i.e the tagging site.
The date and time of gps fix in UTC
Latitude in degrees
Longitude in degrees
Altitude in meters based on satellite positios
Horizontal precision
Vertical precision
The number of satellite fixes
Calculates step metrics including distance, dt, dx, and dy.
step_metrics(sftraj)
step_metrics(sftraj)
sftraj |
an sftrack/sftraj object. sftrack objects will be converted to sftraj internally for calculation. |
#' data("raccoon") raccoon$timestamp <- as.POSIXct(raccoon$timestamp, "EST") burstz <- list(id = raccoon$animal_id, month = as.POSIXlt(raccoon$timestamp)$mon) # Input is a data.frame my_sftraj <- as_sftraj(raccoon, group = burstz, time = "timestamp", error = NA, coords = c("longitude", "latitude") ) step_metrics(my_sftraj)[1:10, ]
#' data("raccoon") raccoon$timestamp <- as.POSIXct(raccoon$timestamp, "EST") burstz <- list(id = raccoon$animal_id, month = as.POSIXlt(raccoon$timestamp)$mon) # Input is a data.frame my_sftraj <- as_sftraj(raccoon, group = burstz, time = "timestamp", error = NA, coords = c("longitude", "latitude") ) step_metrics(my_sftraj)[1:10, ]
Step geometeries in sftraj objects are linestrings going from t1 to t2 of a 'step'. As these are stored at the row level they are not dynamic to changes in t2. step_recalc allows you to recalculate these geometeries if your data.frame has changed because of subsetting or filtering.
step_recalc(x, return = FALSE)
step_recalc(x, return = FALSE)
x |
an sftraj object. |
return |
return step_geometry instead of replacing sftraj object with new step geometry. Defaults to FALSE |
Summarize sftrack objects
summary_sftrack(x)
summary_sftrack(x)
x |
an sftrack object |
Return a list of sf_POINTS or a data.frame from a sftraj object
pts_traj(traj, sfc = FALSE) coord_traj(traj)
pts_traj(traj, sfc = FALSE) coord_traj(traj)
traj |
a trajectory geometery from sf_traj |
sfc |
TRUE/FALSE should the return by an sfc or a list of points. Defaults to FALSE |
#' data("raccoon") raccoon$timestamp <- as.POSIXct(raccoon$timestamp, "EST") burstz <- list(id = raccoon$animal_id, month = as.POSIXlt(raccoon$timestamp)$mon) # Input is a data.frame my_traj <- as_sftraj(raccoon, time = "timestamp", error = NA, coords = c("longitude", "latitude"), group = burstz ) print(my_traj, 5, 10) # extract a list of points pts_traj(my_traj)[1:10] # or a data.frame of points coord_traj(my_traj)[1:10]
#' data("raccoon") raccoon$timestamp <- as.POSIXct(raccoon$timestamp, "EST") burstz <- list(id = raccoon$animal_id, month = as.POSIXlt(raccoon$timestamp)$mon) # Input is a data.frame my_traj <- as_sftraj(raccoon, time = "timestamp", error = NA, coords = c("longitude", "latitude"), group = burstz ) print(my_traj, 5, 10) # extract a list of points pts_traj(my_traj)[1:10] # or a data.frame of points coord_traj(my_traj)[1:10]
This function returns a data.frame of which rows are duplicated and their time stamps.
which_duplicated(data = data.frame(), group, time)
which_duplicated(data = data.frame(), group, time)
data |
a data.frame containing burst or time data (if necessary) |
group |
a list where each entry is a vector of groupings where length == nrow(data)|nrow(time). Or a character vector describing the column name they are located in data |
time |
a vector of as.POSIXct time, or a character of the column name where it can be found in data |