Skip to content

Instantly share code, notes, and snippets.

Last active May 7, 2019 08:10
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Short moveVis example on how to colour paths based on a continuous variable
# use moveVis >= 0.10.2 for this example
# get example data. align movement to unique times and regular resolution
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
# 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)))
# 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)
Copy link

16EAGLE commented May 6, 2019


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment