tween_components {tweenr}R Documentation

Interpolate individual component

Description

This function is much like tween_elements() but with a slightly different syntax and support for many of the newer features such as enter/exits and tween phase identification. Furthermore it uses tidy evaluation for time and id, making it easier to change these on the fly. The biggest change in terms of functionality compared to tween_elements() is that the easing function is now given per column and not per row. If different easing functions are needed for each transition then tween_elements() is needed.

Usage

tween_components(
  .data,
  ease,
  nframes,
  time,
  id = NULL,
  range = NULL,
  enter = NULL,
  exit = NULL,
  enter_length = 0,
  exit_length = 0
)

Arguments

.data

A data.frame with components at different stages

ease

The easing function to use. Either a single string or one for each column in the data set.

nframes

The number of frames to calculate for the tween

time

An unquoted expression giving the timepoint for the different stages of the components. Will be evaluated in the context of .data so can refer to a column from that

id

An unquoted expression giving the component id for each row. Will be evaluated in the context of .data so can refer to a column from that

range

The range of time points to include in the tween. If NULL it will use the range of time

enter, exit

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.

enter_length, exit_length

The lenght of the opening and closing transitions if enter and/or exit is given. Measured in the same units as time

Value

A data.frame with the same columns as .data along with .id giving the component id, .phase giving the state of each component in each frame, and .frame giving the frame membership of each row.

See Also

Other data.frame tween: tween_along(), tween_appear(), tween_elements(), tween_events(), tween_states()

Examples


from_zero <- function(x) {x$x <- 0; x}

data <- data.frame(
  x = c(1, 2, 2, 1, 2, 2),
  y = c(1, 2, 2, 2, 1, 1),
  time = c(1, 4, 10, 4, 8, 10),
  id = c(1, 1, 1, 2, 2, 2)
)

data <- tween_components(data, 'cubic-in-out', nframes = 100, time = time,
                         id = id, enter = from_zero, enter_length = 4)


[Package tweenr version 2.0.3 Index]