# NOT RUN {
library(moveVis)
library(move)
library(ggplot2)
data("move_data", "basemap_data")
# align movement
m <- align_move(move_data, res = 4, unit = "mins")
# }
# NOT RUN {
frames <- frames_spatial(m, map_service = "osm", map_type = "watercolor")
frames[[100]] # take a look at one of the frames
# let's draw a polygon on frames:
data <- data.frame(x = c(8.917, 8.924, 8.924, 8.916, 8.917),
y = c(47.7678, 47.7675, 47.764, 47.7646, 47.7678))
frames = add_gg(frames, gg = expr(geom_path(aes(x = x, y = y), data = data,
colour = "red", linetype = "dashed")), data = data)
# add some text
frames <- add_text(frames, "Static feature", x = 8.9205, y = 47.7633,
colour = "black", size = 3)
frames[[100]]
# add_gg can also be used iteratively to manipulate each frame differently.
# Let's create unique polygons per frame:
# create data.frame containing corner coordinates
data <- data.frame(x = c(8.96, 8.955, 8.959, 8.963, 8.968, 8.963, 8.96),
y = c(47.725, 47.728, 47.729, 47.728, 47.725, 47.723, 47.725))
# make a list from it by replicating it by the length of frames
data <- rep(list(data), length.out = length(frames))
# now alter the coordinates to make them shift
data <- lapply(data, function(x){
y <- rnorm(nrow(x)-1, mean = 0.00001, sd = 0.0001)
x + c(y, y[1])
})
# draw each individual polygon to each frame
frames = add_gg(frames, gg = expr(geom_path(aes(x = x, y = y), data = data,
colour = "black")), data = data)
# add a text label
frames <- add_text(frames, "Dynamic feature", x = 8.959, y = 47.7305,
colour = "black", size = 3)
frames[[100]]
# animate frames to see how the polygons "flip"
animate_frames(frames, out_file = tempfile(fileext = ".mov"))
# you can use add_gg on any list of ggplot2 objects,
# also on frames made using frames_gr
r_list <- basemap_data[[1]]
r_times <- basemap_data[[2]]
frames.gr <- frames_graph(m, r_list = r_list, r_times = r_times, r_type = "gradient",
fade_raster = TRUE, graph_type = "hist", val_by = 0.01)
frames.gr[[100]]
# manipulate the labels, since they are very dense:
# just replace the current scale
frames.gr <- add_gg(frames.gr, expr(scale_x_continuous(breaks=seq(0,1,0.1),
labels=seq(0,1,0.1), expand = c(0,0))))
frames.gr[[100]]
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab