animate_plotly: Animate a ggtour as and HTML widget via '{plotly}'

View source: R/2_ggproto_visualize.r

animate_plotlyR Documentation

Animate a ggtour as and HTML widget via {plotly}

Description

Animates the static ggtour() and added ⁠proto_*()⁠ functions as a {plotly} animation, an .html widget with slider and hover tooltip showing the row number.

Usage

animate_plotly(ggtour, fps = 8, ...)

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.

...

Other arguments passed to plotly::ggplotly.

See Also

Other ggtour animator: animate_gganimate(), 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_origin() +
  proto_basis() +
  proto_point(aes_args = list(color = clas, shape = clas),
              identity_args = list(size = 1.5, alpha = .7))

animate_plotly(ggt, width = 700, height = 450) ## pixels only, no resolution argument

## Example saving to a .html widget, may require additional setup.
if(FALSE){
  anim <- animate_plotly(ggt, fps = 10,
                         width = 700, height = 450) ## in pixels
  
  htmlwidgets::saveWidget(widget = anim,
                          file = "./figures/my_tour.html",
                          selfcontained = TRUE)}


nspyrison/spinifex documentation built on Feb. 7, 2024, 1:10 p.m.