Learn R Programming

spinifex (version 0.3.2)

animate_gganimate: Animate a ggtour as a .gif via {gganimate}

Description

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

Usage

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

Scalar number of Frames Per Second, the speed the animation should play at.

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

Run this code
# NOT RUN {
library(spinifex)
dat     <- scale_sd(penguins[, 1:4])
clas    <- penguins$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))
# }
# NOT RUN {
animate_gganimate(ggt)

if(F){ ## Don't accidentally save file
  ## Alternative arguments storing to a variable for saving
  anim <- animate_gganimate(
    ggt, fps = 10, rewind = TRUE,
    start_pause = 1, end_pause = 2,
    height = 6, width = 10, units = "cm", ## "px", "in", "cm", or "mm."
    res = 150)
  ## Save rendered animation as .gif
  gganimate::anim_save("my_tour.gif",
                       animation = anim,
                       path = "./figures")
  
  ## Alternative renderer saving directly as an .mp4
  animate_gganimate(ggt,
    height = 10, width = 18, units = "cm", ## "px", "in", "cm", or "mm."
    res = 150, ## resolution, not the same as dpi, 100 seems about 1x zoom 
    render = gganimate::av_renderer("./my_tour.mp4")) ## Alternative render
  }
# }

Run the code above in your browser using DataLab