tween_events: Transition in and out of events

View source: R/tween_events.R

tween_eventsR Documentation

Transition in and out of events

Description

This tweening function is a more powerful version of tween_appear(), with support for newer features such as enter/exits and tween phase identification. The tweener treats each row in the data as unique events in time, and creates frames with the correct events present at any given time.

Usage

tween_events(
  .data,
  ease,
  nframes,
  start,
  end = 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

start, end

The start (and potential end) of the event encoded in the row, as unquoted expressions. Will be evaluated in the context of .data so can refer to columns in it. If end = NULL the event will be without extend and only visible in a single frame, unless enter and/or exit is given.

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_components(), tween_elements(), tween_states()

Examples

d <- data.frame(
  x = runif(20),
  y = runif(20),
  time = runif(20),
  duration = runif(20, max = 0.1)
)
from_left <- function(x) {
  x$x <- -0.5
  x
}
to_right <- function(x) {
  x$x <- 1.5
  x
}

tween_events(d, 'cubic-in-out', 50, start = time, end = time + duration,
             enter = from_left, exit = to_right, enter_length = 0.1,
             exit_length = 0.05)


tweenr documentation built on May 29, 2024, 6:32 a.m.