Short moveVis example on how to colour paths based on a continuous variable
# use moveVis >= 0.10.2 for this example | |
library(moveVis) | |
library(move) | |
library(plyr) | |
# get example data. align movement to unique times and regular resolution | |
data("move_data") | |
m.aligned <- align_move(move_data, res = 4, unit = "mins") | |
# let's create some fake continous variable by splitting the moveStack into single tracks | |
m.split <- mapply(x = split(m.aligned), y = c(25, 11, 16), function(x, y){ | |
x$var <- round(sin(seq(0,10, length.out = length(x)))*y)+y+1 | |
return(x) | |
}) | |
# now, each move object has a column "var" with some values (this could be anything, | |
# e.g. heart rate, temperature etc.) | |
# let's create a colour ramp function and assign colours for each value in "var" | |
colfun <- colorRampPalette(c("navy", "blue", "lightblue", "purple", "violetred")) | |
m.split <- lapply(m.split, function(x){ | |
x$colour <- mapvalues(x$var, 1:max(x$var), colfun(max(x$var))) | |
return(x) | |
}) | |
# now, we have a colour column with individual colours per value for each individual | |
# finally, merge the tracks back togehter into a stack... | |
m <- moveStack(m.split) | |
# ...and create frames from it | |
frames <- frames_spatial(m, map_service = "mapbox", map_type = "satellite", map_token = "YOUR_MAPBOX_TOKEN", | |
trace_show = T, path_legend = F, equidistant = F, path_fade = T) %>% | |
add_timestamps(type = "label") %>% | |
add_progress() %>% | |
add_northarrow(colour = "white") %>% | |
add_scalebar(colour = "white") %>% | |
add_labels(x = "Longitude", y = "Latitude") | |
# animate the frames | |
animate_frames(frames, "moveVis_colours_by_variable.gif", width = 800, height = 550, | |
end_pause = 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.