use moveVis >= 0.10.1 for this example
April 15, 2019 · View on GitHub
library(moveVis) library(move)
data("move_data")
align movement to unique times and regular resolution
m.aligned <- align_move(move_data, res = 4, unit = "mins") m.split <- split(m.aligned)
let's use the first individual and colour it by behavioral segment
ts.m <- timestamps(m.split[[1]])
define behavioral change points and assoicate the segment with colours
cp.m <- list(green = min(ts.m), red = as.POSIXct("2018-05-15 12:00:00", tz = "UTC"), blue = as.POSIXct("2018-05-15 14:00:00", tz = "UTC"), orange = as.POSIXct("2018-05-15 16:00:00", tz = "UTC"))
iterate through change points and assign colours for segments between change points
col.m <- unlist(mapply(x = cp.m, y = c(cp.m[2:length(cp.m)], max(ts.m)), col = names(cp.m), function(x, y, col){ rep(col, length(which(ts.m >= x & ts.m < y))) }, SIMPLIFY = F, USE.NAMES = F))
add colour for the last timestamp to match lengths
col.m <- c(col.m, tail(col.m, n = 1))
assign colour column, which is recoginced by moveVis
m.split[[1]]$colour <- col.m
for the other individual, let's use static colours wihout changes
m.split[[2]]colour <- rep("purple", nrow(m.split[[3]]))
stack the move split back together
m.stack <- moveStack(m.split)
create frames and disable path legend
legend would assoicate initial path colours with individual names: makes no sense, since colours for individual 1 are changing over time
frames <- frames_spatial(m.stack, map_service = "osm", map_type = "terrain_bg", path_legend = F)
check frame 80 to see, how individual 1 transits in colour
frames[[80]]
animate frames
animate_frames(frames, out_file = "animation.mov", overwrite = T)