| # use moveVis >= 0.10.1 for this example | |
| 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("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 | |
| frames[[80]] | |
| # animate frames | |
| animate_frames(frames, out_file = "animation.mov", overwrite = T) |
This comment has been minimized.
This comment has been minimized.
|
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! |
This comment has been minimized.
This comment has been minimized.
|
Any chance it would be possible to post a simpler example? I'm finding
to be pretty difficult to interpret. I'm hoping to do something very simple - color any tracks that go north of 65.7 latitude to turn red but have no idea how to subset/work with MoveStack objects... Thanks! EDIT:
|
This comment has been minimized.