tween_path | R Documentation |
This function is equivalent to tweenr::tween_state()
but expects the data
to have an x
and y
column and encode paths.
tween_path( .data, to, ease, nframes, id = NULL, enter = NULL, exit = NULL, match = TRUE )
.data |
A data.frame to start from. If |
to |
A data.frame to end at. It must contain the same columns as .data
(exluding |
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 |
enter, exit |
functions that calculate a start state for new observations
that appear in |
match |
Should polygons be matched by id? If |
A data.frame containing intermediary states
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.
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.
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.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.