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.
gen_keyframe(keyframe = NULL, pause = 0)
add_pause(.data, pause = 0)
add_keyframe(
.data,
keyframe,
ease,
length,
id = NULL,
enter = NULL,
exit = NULL
)
A data frame to use as a keyframe state
The length of the pause at the current keyframe
A data.frame to start from. If .data
is the result of a prior
tween, only the last frame will be used for the tween. The new tween will
then be added to the prior tween
The easing function to use. Either a single string or one for each column in the data set.
The length of the transition
The column to match observations on. If NULL
observations will be
matched by position. See the Match, Enter, and Exit section for more
information.
functions that calculate a start state for new observations
that appear in to
or an end state for observations that are not present in
to
. If NULL
the new/old observations will not be part of the tween. The
function gets a data.frame with either the start state of the exiting
observations, or the end state of the entering observations and must return
a modified version of that data.frame. See the Match, Enter, and Exit
section for more information.
A keyframe_generator
object
Other Other generators:
gen_along()
,
gen_at()
,
gen_components()
,
gen_events()
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)
#> country population .phase
#> 1 Denmark 5314868.8 transition
#> 2 Sweden 10157434.4 transition
#> 3 Norway 3657434.4 transition
#> 4 Finland 944606.4 enter