gganimate (version 1.0.2)

transition_reveal: Reveal data along a given dimension

Description

This transition allows you to let data gradually appear, based on a given time dimension. In contrast to e.g. transition_time() transition_reveal() calculates intermediary values at exact positions instead of coercing raw values into the closest frame. It further keeps old data for path and polygon type layers so that they are gradually build up instead of being a set of disconnected segments as will happen when using transition_time() and shadow_mark() together.

Usage

transition_reveal(along, range = NULL, keep_last = TRUE, id)

Arguments

along

An unquoted expression giving the dimension to tween along. For a gradually revealing time series this should be set to the same as the x aesthetic.

range

The time range to animate. If NULL it will be set to the range of along

keep_last

For non-path/polygon layers should the last row be kept for subsequent frames.

id

Deprecated

Label variables

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

  • frame_along gives the position on the along-dimension that the current frame corresponds to

Object permanence

transition_reveal uses the group aesthetic of each layer to identify which rows in the input data correspond to the same graphic element and will therefore define a a whole to be revealed over the animation. The group aesthetic, if not set, will be calculated from the interaction of all discrete aesthetics in the layer (excluding label), so it is often better to set it explicetly when animating, to make sure your data is interpreted in the right way. If the group aesthetic is not set, and no discrete aesthetics exists then all rows will have the same group.

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_manual, transition_null, transition_states, transition_time

Examples

Run this code
# NOT RUN {
anim <- ggplot(airquality, aes(Day, Temp, group = Month)) +
  geom_line() +
  transition_reveal(Day)

# Non-paths will only show the current position, not the history
anim1 <- ggplot(airquality, aes(Day, Temp, group = Month)) +
  geom_line() +
  geom_point(colour = 'red', size = 3) +
  transition_reveal(Day)

# Points can be kept by giving them a unique group and set `keep = TRUE` (the
# default)
anim2 <- ggplot(airquality, aes(Day, Temp, group = Month)) +
  geom_line() +
  geom_point(aes(group = seq_along(Day))) +
  geom_point(colour = 'red', size = 3) +
  transition_reveal(Day)

# }

Run the code above in your browser using DataCamp Workspace