This set of functions can be used to interpolate between single data types, i.e. data not part of data.frames but stored in vectors. All functions come in two flavours: the standard and a *_t version. The standard reads the data as a list of states, each tween matched element-wise from state to state. The *_t version uses the transposed representation where each element is a vector of states. The standard approach can be used when each tween has the same number of states and you want to control the number of point in each state transition. The latter is useful when each tween consists of different numbers of states and/or you want to specify the total number of points for each tween.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
tween(data, n, ease = "linear") tween_t(data, n, ease = "linear") tween_colour(data, n, ease = "linear") tween_color(data, n, ease = "linear") tween_colour_t(data, n, ease = "linear") tween_color_t(data, n, ease = "linear") tween_constant(data, n, ease = "linear") tween_constant_t(data, n, ease = "linear") tween_date(data, n, ease = "linear") tween_date_t(data, n, ease = "linear") tween_datetime(data, n, ease = "linear") tween_datetime_t(data, n, ease = "linear") tween_numeric(data, n, ease = "linear") tween_numeric_t(data, n, ease = "linear")
A list of vectors or a single vector. In the standard functions
each element in the list must be of equal length; for the *_t functions
lengths can differ. If a single vector is used it will be eqivalent to using
The number of elements per transition or tween. See details
The easing function to use for each transition or tween. See
details. Defaults to
tween_t are wrappers around the other functions that tries to guess
the type of input data and choose the appropriate tween function. Unless you
have data that could be understood as a colour but is in fact a character
vector it should be safe to use these wrappers. It is probably safer and more
verbose to use the explicit functions within package code as they circumvent
the type inference and checks whether the input data matches the tween
tween_numeric will provide a linear interpolation between the points based on
the sequence returned by the easing function.
converts to numeric, produces the tweening, and converts back again.
tween_colour converts colours into Lab and does the interpolation there,
converting back to sRGB after the tweening is done.
tween_constant is a
catchall that converts the input into character and interpolates by switching
between states halfway through the transition.
The meaning of the
ease arguments differs somewhat
between the standard and *_t versions of the functions. In the standard
ease refers to the length and easing function of
each transition, being recycled if necessary to
length(data) - 1. In
the *_t functions
ease refers to the total length of each
tween and the easing function to be applied to all transition for each tween.
The will both be recycled to
A list with an element for each tween. That means that the length of
the return is equal to the length of the elements in
data for the
standard functions and equal to the length of
data for the *_t
tween_numeric_t) is superficially equivalent to
stats::approx(), but there are differences.
stats::approx() will create evenly spaced points, at the expense
of not including the actual points in the input, while the reverse is true
tween_numeric. Apart from that
tween_numeric of course supports easing
functions and is vectorized.
1 2 3
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.