Animates the ggplot return of ggtour() and added proto_*() functions as a .gif without interaction, through use of {gganimate}.

animate_gganimate(
  ggtour,
  fps = 8,
  rewind = FALSE,
  start_pause = 1,
  end_pause = 1,
  ...
)

Arguments

ggtour

A grammar of graphics tour with appended protos added. A return from ggtour() + proto_*().

fps

Number of Frames Per Second, the speed resulting animation.

rewind

Whether or not the animation should play backwards, in reverse order once reaching the end. Defaults to FALSE.

start_pause

The duration in seconds to wait before starting the animation. Defaults to 1 second.

end_pause

The duration in seconds to wait after ending the animation, before it restarts from the first frame. Defaults to 1 second.

...

Other arguments passed to gganimate::animate.

See also

gganimate::animate

Other ggtour animator: animate_plotly(), filmstrip()

Examples

library(spinifex)
dat     <- scale_sd(penguins_na.rm[, 1:4])
clas    <- penguins_na.rm$species
bas     <- basis_pca(dat)
mv      <- manip_var_of(bas)
mt_path <- manual_tour(bas, manip_var = mv)

ggt <- ggtour(mt_path, dat, angle = .3) +
  proto_default(aes_args = list(color = clas, shape = clas),
                identity_args = list(size = 1.5, alpha = .7))
# \donttest{
## Default .gif rendering
animate_gganimate(ggt)

if(FALSE){ ## Don't accidentally save file
  ## Option arguments, rendering to default .gif
  anim <- animate_gganimate(
    ggt, fps = 10, rewind = TRUE,
    start_pause = 1, end_pause = 2,
    height = 10, width = 15, units = "cm", ## "px", "in", "cm", or "mm."
    res = 200 ## resolution, pixels per dimension unit I think
  )
  ## Save rendered animation
  gganimate::anim_save("my_tour.gif",
                       animation = anim,
                       path = "./figures")
  
  ## Alternative renderer saving directly to .mp4
  animate_gganimate(ggt, fps = 5,
    height = 4, width = 6, units = "in", ## "px", "in", "cm", or "mm."
    res = 200, ## resolution, pixels per dimension unit I think
    renderer = gganimate::av_renderer("./my_tour.mp4"))
}
# }