Learn R Programming

gganimate (version 1.0.9)

transition_manual: Create an animation by specifying the frame membership directly

Description

This transition allows you to map a variable in your data to a specific frame in the animation. No tweening of data will be made and the number of frames in the animation will be decided by the number of levels in the frame variable.

Usage

transition_manual(frames, ..., cumulative = FALSE)

Arguments

frames

The unquoted name of the column holding the frame membership.

...

Additional variables

cumulative

Keep data from previous frames as part of the current frame data

Label variables

transition_states makes the following variables available for string literal interpretation, in addition to the general ones provided by animate():

  • previous_frame The name of the last frame the animation was at

  • current_frame The name of the current frame

  • next_frame The name of the next frame in the animation

Object permanence

transition_manual does not link rows across data to the same graphic element. Every frame is a discrete state and no animation between the states is done.

Computed Variables

It is possible to use variables calculated by the statistic to define the transition. Simply inclose the variable in stat() in the same way as when using computed variables in aesthetics.

See Also

Other transitions: transition_components(), transition_events(), transition_filter(), transition_layers(), transition_null(), transition_reveal(), transition_states(), transition_time()

Examples

Run this code
anim <- ggplot(mtcars, aes(factor(gear), mpg)) +
  geom_boxplot() +
  transition_manual(gear)

# Using `cumulative = TRUE` to keep data from older frames
anim2 <- ggplot(mtcars, aes(factor(gear), mpg)) +
  geom_boxplot() +
  transition_manual(gear, cumulative = TRUE)

# Use `factor()` to set the order of the frames
anim3 <- ggplot(mtcars, aes(factor(gear), mpg)) +
  geom_boxplot() +
  transition_manual(factor(gear, levels = c('4', '3', '5')))

Run the code above in your browser using DataLab