Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Short moveVis example on how to assign multiple path colours per individual to indicate e.g. behavioral segments
# use moveVis >= 0.10.1 for this example
# 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)))
# 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("orange", nrow(m.split[[2]]))
m.split[[3]]$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
# animate frames
animate_frames(frames, out_file = "", overwrite = T)

This comment has been minimized.

Copy link
Owner Author

commented May 6, 2019



This comment has been minimized.

Copy link

commented Oct 12, 2019

this is a fantastic feature. how would I colour my trace_colour the same as my unique path_colour? it would be nice to have the trace stay behind, but in the path colour rather than the default white trace colour. I'm struggling with how to apply the path_colour to the trace. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.