animation_opts | R Documentation |
Animations can be created by either using the frame
argument in
plot_ly()
or the (unofficial) frame
ggplot2 aesthetic in
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 animation_opts()
.
animation_opts(
p,
frame = 500,
transition = frame,
easing = "linear",
redraw = TRUE,
mode = "immediate"
)
animation_slider(p, hide = FALSE, ...)
animation_button(p, ..., label)
p |
a plotly object. |
frame |
The amount of time between frames (in milliseconds).
Note that this amount should include the |
transition |
The duration of the smooth transition between frames (in milliseconds). |
easing |
The type of transition easing. See the list of options here https://github.com/plotly/plotly.js/blob/master/src/plots/animation_attributes.js |
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. |
mode |
Describes how a new animate call interacts with currently-running
animations. If |
hide |
remove the animation slider? |
... |
for |
label |
a character string used for the animation button's label |
Carson Sievert
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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.