File: animation.Rd

package info (click to toggle)
r-cran-plotly 4.10.4%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 30,636 kB
  • sloc: javascript: 195,272; sh: 24; makefile: 6
file content (102 lines) | stat: -rw-r--r-- 3,607 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/animate.R
\name{animation_opts}
\alias{animation_opts}
\alias{animation}
\alias{animation_slider}
\alias{animation_button}
\title{Animation configuration options}
\usage{
animation_opts(
  p,
  frame = 500,
  transition = frame,
  easing = "linear",
  redraw = TRUE,
  mode = "immediate"
)

animation_slider(p, hide = FALSE, ...)

animation_button(p, ..., label)
}
\arguments{
\item{p}{a plotly object.}

\item{frame}{The amount of time between frames (in milliseconds).
Note that this amount should include the \code{transition}.}

\item{transition}{The duration of the smooth transition between
frames (in milliseconds).}

\item{easing}{The type of transition easing. See the list of options here
\url{https://github.com/plotly/plotly.js/blob/master/src/plots/animation_attributes.js}}

\item{redraw}{Trigger a redraw of the plot at completion of the transition?
A redraw may significantly impact performance, but may be necessary to
update graphical elements that can't be transitioned.}

\item{mode}{Describes how a new animate call interacts with currently-running
animations. If \code{immediate}, current animations are interrupted and
the new animation is started. If \code{next}, the current frame is allowed
to complete, after which the new animation is started. If \code{afterall}
all existing frames are animated to completion before the new animation
is started.}

\item{hide}{remove the animation slider?}

\item{...}{for \code{animation_slider}, attributes are passed to a special
layout.sliders object tied to the animation frames.
The definition of these attributes may be found here
\url{https://github.com/plotly/plotly.js/blob/master/src/components/sliders/attributes.js}
For \code{animation_button}, arguments are passed to a special
layout.updatemenus button object tied to the animation
\url{https://github.com/plotly/plotly.js/blob/master/src/components/updatemenus/attributes.js}}

\item{label}{a character string used for the animation button's label}
}
\description{
Animations can be created by either using the \code{frame} argument in
\code{\link[=plot_ly]{plot_ly()}} or the (unofficial) \code{frame} ggplot2 aesthetic in
\code{\link[=ggplotly]{ggplotly()}}. By default, animations populate a play button
and slider component for controlling the state of the animation
(to pause an animation, click on a relevant location on the slider bar).
Both the play button and slider component transition between frames according
rules specified by \code{\link[=animation_opts]{animation_opts()}}.
}
\examples{
\dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf}

df <- data.frame(
  x = c(1, 2, 2, 1, 1, 2),
  y = c(1, 2, 2, 1, 1, 2),
  z = c(1, 1, 2, 2, 3, 3)
)
plot_ly(df) \%>\%
  add_markers(x = 1.5, y = 1.5) \%>\%
  add_markers(x = ~x, y = ~y, frame = ~z)

# it's a good idea to remove smooth transitions when there is
# no relationship between objects in each view
plot_ly(mtcars, x = ~wt, y = ~mpg, frame = ~cyl) \%>\%
  animation_opts(transition = 0)

# works the same way with ggplotly
if (interactive()) {
  p <- ggplot(txhousing, aes(month, median)) +
    geom_line(aes(group = year), alpha = 0.3) +
    geom_smooth() +
    geom_line(aes(frame = year, ids = month), color = "red") +
    facet_wrap(~ city)
 
  ggplotly(p, width = 1200, height = 900) \%>\%
    animation_opts(1000)
}

  
#' # for more, see https://plotly.com/r/animating-views.html
\dontshow{\}) # examplesIf}
}
\author{
Carson Sievert
}