title | name | permalink | description | layout | thumbnail | language | page_type | has_thumbnail | display_as | order | output | ||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Intro to Animations | Examples | Plotly |
Intro to Animations |
ggplot2/animations/ |
How to create animations in ggplot2 with Plotly. |
base |
thumbnail/animations.gif |
ggplot2 |
example_index |
true |
animations |
1 |
|
Plotly's R library is free and open source!
Get started by downloading the client and reading the primer.
You can set up Plotly to work in online or offline mode.
We also have a quick-reference cheatsheet (new!) to help you get started!
Version 4 of Plotly's R package is now available!
Check out this post for more information on breaking changes and new features available in this version.
library(plotly)
packageVersion('plotly')
## [1] '4.7.0'
Now, along with data
and layout
, frames
is added to the keys that figure
allows. Your frames
key points to a list of figures, each of which will be cycled through upon instantiation of the plot.
library(plotly)
df <- data.frame(
x = c(1,2,3,4),
y = c(1,2,3,4),
f = c(1,2,3,4)
)
p <- ggplot(df, aes(x, y)) +
geom_point(aes(frame = f))
p <- ggplotly(p)
# Create a shareable link to your chart
# Set up API credentials: https://plot.ly/r/getting-started
chart_link = api_create(p, filename="gganimations/basic")
chart_link
library(plotly)
library(gapminder)
p <- ggplot(gapminder, aes(gdpPercap, lifeExp, color = continent)) +
geom_point(aes(size = pop, frame = year, ids = country)) +
scale_x_log10()
p <- ggplotly(p)
# Create a shareable link to your chart
# Set up API credentials: https://plot.ly/r/getting-started
chart_link = api_create(p, filename="gganimations/mulitple-trace")
chart_link
library(plotly)
p <- p %>%
animation_opts(
1000, easing = "elastic", redraw = FALSE
)
# Create a shareable link to your chart
# Set up API credentials: https://plot.ly/r/getting-started
chart_link = api_create(p, filename="gganimations/animation-options")
chart_link
library(plotly)
p <- p %>%
animation_button(
x = 1, xanchor = "right", y = 0, yanchor = "bottom"
)
# Create a shareable link to your chart
# Set up API credentials: https://plot.ly/r/getting-started
chart_link = api_create(p, filename="gganimations/button-options")
chart_link
library(plotly)
p <- p %>%
animation_slider(
currentvalue = list(prefix = "YEAR ", font = list(color="red"))
)
# Create a shareable link to your chart
# Set up API credentials: https://plot.ly/r/getting-started
chart_link = api_create(p, filename="gganimations/slider-options")
chart_link
library(plotly)
library(gapminder)
p <- ggplot(gapminder, aes(gdpPercap, lifeExp, color = continent)) +
geom_point(aes(size = pop, frame = year, ids = country)) +
scale_x_log10()
p <- ggplotly(p) %>%
animation_opts(
1000, easing = "elastic", redraw = FALSE
) %>%
animation_button(
x = 1, xanchor = "right", y = 0, yanchor = "bottom"
) %>%
animation_slider(
currentvalue = list(prefix = "YEAR ", font = list(color="red"))
)
# Create a shareable link to your chart
# Set up API credentials: https://plot.ly/r/getting-started
chart_link = api_create(p, filename="gganimations/advanced")
chart_link
To read more on animations see The Plotly Book.