view_step: Follow the data in steps

View source: R/view-step.R

view_stepR Documentation

Follow the data in steps

Description

This view is a bit like view_follow() but will not match the data in each frame. Instead it will switch between being static and zoom to the range of the data. It is a great pairing with transition_states() as it can move the view while the data is static and then be static while the data moves. The standard version will look at the data present in the calculated frames and set the ranges based on that, while the ⁠_manual⁠ version will allow you to define your own ranges.

Usage

view_step(
  pause_length = 1,
  step_length = 1,
  nsteps = NULL,
  look_ahead = pause_length,
  delay = 0,
  include = TRUE,
  ease = "cubic-in-out",
  wrap = TRUE,
  pause_first = FALSE,
  fixed_x = FALSE,
  fixed_y = FALSE,
  exclude_layer = NULL,
  aspect_ratio = 1
)

view_step_manual(
  pause_length = 1,
  step_length = 1,
  xmin,
  xmax,
  ymin,
  ymax,
  delay = 0,
  ease = "cubic-in-out",
  wrap = TRUE,
  pause_first = FALSE,
  fixed_x = FALSE,
  fixed_y = FALSE,
  exclude_layer = NULL,
  aspect_ratio = 1
)

Arguments

pause_length

The relative length the view will be kept static. Will be recycled to match the number of steps

step_length

The relative length the view will use to transition to the new position. Will be recycled to match the number of steps

nsteps

The number of steps. If NULL it will be set to the max length of pause_length or step_length

look_ahead

A relative length to look ahead in the animation to get the new zoom area. Allow the view to zoom to where the data will be

delay

A relative length to switch the view back and forth relative to the actual frames. E.g. if delay is calculated to 5 frames, frame 6 will get the view intended for frame 1.

include

Should the steps include both the start and end frame range

ease

The easing function used for the step

wrap

As in transition_states(). Should the view wrap around and zoom back to the first state.

pause_first

Should the view start with a pause. The default is to start with a step so that it is aligned to the static period in transition_states()

fixed_x, fixed_y

Either a logical indicating if the dimension should not be modified by the view, or a numeric vector giving the lower and upper bounds of the dimension. For the latter, an NA value will be substituted for whatever is calculated by the view (e.g. fixed_x = c(0, NA)) will fix the minimum x value to 0 and let the view calculate the upper bound.

exclude_layer

Integer vector of layer indices that should be ignored when calculating the view

aspect_ratio

If the coord is fixed, ensure that the view matches the given aspect ratio. Will override anything given in fixed_x/fixed_y

xmin, xmax, ymin, ymax

Vectors of even length defining the boundaries of the different views to go through

See Also

Other views: view_follow(), view_static(), view_zoom()

Examples

anim <- ggplot(iris, aes(Petal.Length, Petal.Width)) +
  geom_point() +
  transition_states(Species, transition_length = 2, state_length = 1) +
  view_step(pause_length = 2, step_length = 1, nsteps = 3)

# Default is to include the data from the two states you're stepping between
# but this can be turned off
anim <- ggplot(iris, aes(Petal.Length, Petal.Width)) +
  geom_point() +
  transition_states(Species, transition_length = 2, state_length = 1) +
  view_step(pause_length = 2, step_length = 1, nsteps = 3, include = FALSE)

# Default is to work off-beat of transition_states so that view changes while
# data is static. Setting pause_first=TRUE changes this
anim <- ggplot(iris, aes(Petal.Length, Petal.Width)) +
  geom_point() +
  transition_states(Species, transition_length = 2, state_length = 1) +
  view_step(pause_length = 1, step_length = 2, nsteps = 3, pause_first = TRUE)

# If the transition doesn't wrap, then the view shouldn't either
anim <- ggplot(iris, aes(Petal.Length, Petal.Width)) +
  geom_point() +
  transition_states(Species, transition_length = 2, state_length = 1, wrap = FALSE) +
  view_step(pause_length = 2, step_length = 1, nsteps = 3, wrap = FALSE)


gganimate documentation built on May 29, 2024, 2:58 a.m.