tween_path: Transition between path data frames

Description Usage Arguments Value Aligning paths Cutting paths Multipaths

View source: R/tween_path.R

Description

This function is equivalent to tweenr::tween_state() but expects the data to have an x and y column and encode paths.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
tween_path(
  .data,
  to,
  ease,
  nframes,
  id = NULL,
  enter = NULL,
  exit = NULL,
  match = TRUE
)

Arguments

.data

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

to

A data.frame to end at. It must contain the same columns as .data (exluding .frame)

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

id

The column to match observations on. If NULL observations will be matched by position. See the Match, Enter, and Exit section for more information.

enter

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.

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.

match

Should polygons be matched by id? If FALSE then polygons will be matched by shortest distance and if any state has more polygons than the other, the other states polygons will be chopped up so the numbers match.

Value

A data.frame containing intermediary states

Aligning paths

There is less work required to align paths than there is to align polygons, simply because no rotation is possible/required, and the notion of clockwise winding order is not meaningful in the scope of paths. Still, paths need to be matched and the number of points in each pair of matched paths must be equal. Paths are matched based on relative length rather than on position and seek to minimize the change in length during transition. This is chosen from the point of view that huge elongation or contraction are much more distracting than longer travel distances.

Cutting paths

If the number of paths to transition between is not even, some of the paths need to be cut in order to succesfully match the paths. The cuts are distributed based on the same algorithm that distributes cuts in polygons and seek to cut the lines into as even-length pieces as possible.

Multipaths

It is possible to encode multiple paths with the same id be separating them with a NA row, much in the same way as holes are encoded in polygons. If paths are not matched based on id (match = FALSE) then multipaths will simply be split into separate paths. On the other hand, if paths are matched by id all paths within a multipath will transition into the (multi)path that has the same id in the other state.


transformr documentation built on July 8, 2020, 6:27 p.m.