load packages and the data
library(ggplot2)
library(gganimate)
library(lubridate)
##
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
##
## date, intersect, setdiff, union
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(viridis)
## Loading required package: viridisLite
dats <- read.csv("datos/ovejas_UTM_2019.csv")
drops <- c("X")
dats <- dats[ , !(names(dats) %in% drops)]
dats$time <- ymd_hms(dats$time)
dats <- dats[-which(is.na(dats$time)), ]
run animation on selected date and time. Here I choose two days of data when there’s more than one group.
tmp = which(dats$time > ymd_h("2019-03-02 00")
& dats$time < ymd_h("2019-03-03 24")
& dats$HDOP < 1.2 )
# plot(dats$Easting[tmp], dats$Northing[tmp], asp = 1)
d = dats[tmp,]
p <- ggplot(d) +
geom_point(aes(lon, lat, group = id, colour = as.factor(id)), size = 2) +
scale_color_viridis(discrete=TRUE, alpha = 0.4, option = "B") +
coord_sf(xlim = range(d$lon), ylim = range(d$lat)) +
transition_components(time) +
shadow_trail(distance = 0.01, size = 0.3, alpha = alpha/2, max_frames = 10)
gganimate::animate(p, nframes = 300, fps = 10)
Now two days when they are mostly together
tmp = which(dats$time > ymd_h("2019-05-02 00")
& dats$time < ymd_h("2019-05-03 24")
& dats$HDOP < 1.2 )
# plot(dats$Easting[tmp], dats$Northing[tmp], asp = 1)
d = dats[tmp,]
p <- ggplot(d) +
geom_point(aes(lon, lat, group = id, colour = as.factor(id)), size = 2) +
scale_color_viridis(discrete=TRUE, alpha = 0.4, option = "B") +
coord_sf(xlim = range(d$lon), ylim = range(d$lat)) +
transition_components(time) +
shadow_trail(distance = 0.01, size = 0.3, alpha = alpha/2, max_frames = 10)
gganimate::animate(p, nframes = 300, fps = 10)