| gen_keyframe {tweenr} | R Documentation | 
Generator for keyframe based tweening
Description
This is a generator version of tween_state() and its utility functions. It
returns a generator that can be used with get_frame() and
get_raw_frames() to extract frames for a specific time point scaled between
0 and 1.
Usage
gen_keyframe(keyframe = NULL, pause = 0)
add_pause(.data, pause = 0)
add_keyframe(
  .data,
  keyframe,
  ease,
  length,
  id = NULL,
  enter = NULL,
  exit = NULL
)
Arguments
| keyframe | A data frame to use as a keyframe state | 
| pause | The length of the pause at the current keyframe | 
| .data | A data.frame to start from. If  | 
| ease | The easing function to use. Either a single string or one for each column in the data set. | 
| length | The length of the transition | 
| id | The column to match observations on. If  | 
| enter,exit | functions that calculate a start state for new observations
that appear in  | 
Value
A keyframe_generator object
See Also
Other Other generators: 
gen_along(),
gen_at(),
gen_components(),
gen_events()
Examples
df1 <- data.frame(
  country = c('Denmark', 'Sweden', 'Norway'),
  population = c(5e6, 10e6, 3.5e6)
)
df2 <- data.frame(
  country = c('Denmark', 'Sweden', 'Norway', 'Finland'),
  population = c(6e6, 10.5e6, 4e6, 3e6)
)
df3 <- data.frame(
  country = c('Denmark', 'Norway'),
  population = c(10e6, 6e6)
)
to_zero <- function(x) {
  x$population <- 0
  x
}
gen <- gen_keyframe(df1, 10) %>%
  add_keyframe(df2, 'cubic-in-out', 35, id = country, enter = to_zero) %>%
  add_pause(10) %>%
  add_keyframe(df3, 'cubic-in-out', 35, id = country, enter = to_zero,
               exit = to_zero) %>%
  add_pause(10)
get_frame(gen, 0.25)