How to tell gganimate to stop animating between large time periods when data is not present

Viewed 147

I am using gganimate to plot animal movement tracks over time. The animal is only present at certain locations at certain times of year. I am using transition_states to animate across time with geom_points, however gganimate makes it appear as if there is no time gaps in the data. E.g. it jumps from one location to the next even if there are 2 or more weeks separating the two locations.

Is there a way to for gganimate to have no animation between chunks of time (i.e. be a blank map), rather than jumping to the next time frame?

Many thanks for some help!

Below is a portion of my code:

library(ggmap)
library(gganimate)
library(maps)
library(ggplot2)
library(ggthemes)


#create bounding box for my location
bbox <- myLocation <- c(-156.49, 18.79, -154.98, 20.30)
ggmap <- get_map(location = bbox, source = "google", maptype = "hybrid", zoom=10)
map = ggmap(ggmap)
map

#create dataframe

Date = c("2018-10-07", "2018-10-14", "2018-10-21", "2018-10-28", "2018-11-04", "2018-11-11", "2018-11-18", "2018-11-25", "2018-12-02", "2018-12-09", "2018-12-16", 
         "2018-12-23")
Longitude = c(19.19833, 19.07667, 19.50600, 19.38500, 19.55140, 19.58500, 19.19833, 19.07667, 19.50600, 19.38500, 19.55140, 19.58500)
Latitude = c(-155.9483, -155.9567, -156.1567, -155.9867, -156.0506, -156.0320, -155.9483, -155.9567, -156.1567, -155.9867, -156.0506, -156.0320)
Station.Name = c("B", "TT", "F", "C", "Cage", "VV", "B", "TT", "F", "C", "Cage", "VV")

df = data.frame(Date, Longitude, Latitude, Station.Name)
str(df)
df$Date = as.Date(df$Date)
df$Station.Name = as.factor(df$Station.Name)

#create animation with gganimate
anim = map + 
  theme(text = element_text(size = 17))+
  geom_point(data = df, aes(x = Longitude, y = Latitude, group=interaction(Date, Station.Name)), color="#C75058", size=5) +
  labs(title = "Movement tracks",
       subtitle = "Date:{closest_state}", #this is gframe alone
       x = "Longitude", y = "Latitude")+
  transition_states(states = Date,
                    transition_length = 3, # 3/4 of total time for transitions
                    state_length = 1) +  exit_disappear()
anim
0 Answers
Related