library(moveVis)
library(move)
library(proj4)
library(dplyr)
moveVIS
Load libraries
Load Data
<- read.table(file = "data/clean_dataLatLong.txt", sep = "\t", stringsAsFactors = TRUE)
datos$timestamp<- as.POSIXct(datos$timestamp, format = "%Y-%m-%d %H:%M", tz = "UTC")# "POSIXct" representing calendar dates and times. datos
Subset dataset to produce a shorter video
<- datos %>% dplyr::filter(id %in% c("T4HS_6601","T4HS_6599")) %>%
datos22 filter(timestamp > "2019-01-13 12:00:00" & timestamp <"2019-02-13 12:00:00")# selecting the individuals in formetor, 1 month
Convert a data.frame into a move or moveStack object In R
the notation used to describe the CRS is proj4string from the PROJ.4 library
Use df2move to convert the data.frame into a moveStack. (lat-long format)
<- df2move(datos22, proj =
formentor_move"+init=epsg:4326 +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 ",
x = "longitude", y = "latitude", time = "timestamp", track_id = "id")
Align move_data to a uniform time scale
<- align_move(formentor_move, res = 240, digit = 0, unit = "mins") m
Temporal resolution of 240 [mins] is used to align trajectories.
Create spatial frames with a Satellite basemap
<- frames_spatial(m, path_colours = c("green", "red"),
frames map_service = "mapbox", map_type = "satellite", map_token = "pk.eyJ1IjoibWlhaGFybyIsImEiOiJjanVvNTZud3AyMWJlM3luN2E5NjU3ODIyIn0.Bsms_f8eZVJtHrjiG74fnw", alpha = 1, margin_factor = 1.4, map_res = 1,
path_size = 2, path_alpha = 0.7, path_legend_title = " ", tail_length = 12, tail_size = 1, tail_colour = "white") %>%
add_labels(x = "longitude", y = "latitude") %>% # add some customizations, such as axis labels
add_northarrow(colour = "yellow") %>%
add_scalebar(distance = 0.5, colour = "yellow") %>%
add_timestamps(m, type = "text", colour = "yellow", size=8) %>%
add_progress()
Checking temporal alignment...
Processing movement data...
Approximated animation duration: ≈ 7.44s at 25 fps for 186 frames
Retrieving and compositing basemap imagery...
Loading basemap 'satellite' from map service 'mapbox'...
Assigning raster maps to frames...
Warning: Argument 'm' is deprecated and thus being ignored.
100]] frames[[
Animate frames
#animate_frames(frames,fps = 10, out_file = "C:/Users/mglib/OneDrive/Doctorado/collares/TRAJ/formentor_10.mp4")