transition_reveal: Reveal data along a given dimension

View source: R/transition_reveal.R

transition_revealR Documentation

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)

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.

Label variables

transition_reveal 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 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 explicitly 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

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)

# Since ggplot2 3.4 geom_ribbon and geom_area has used stat_align
# This stat is incompatible with transition_reveal when applied before
# stats are calculated
anim3 <- ggplot(airquality, aes(Day, Temp, group = Month)) +
  geom_area() +
  transition_reveal(Day)

# This can be fixed by either reverting to use stat_identity
anim4 <- ggplot(airquality, aes(Day, Temp, group = Month)) +
  geom_area(stat = "identity") +
  transition_reveal(Day)

# Or by applying the transition after the stat
anim5 <- ggplot(airquality, aes(Day, Temp, group = Month)) +
  geom_area() +
  transition_reveal(after_stat(x))


dgrtwo/gganimate documentation built on March 3, 2024, 8:15 a.m.