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.

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")

Arguments

data

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 as.list(data) for the standard functions and list(data) for the *_t functions.

n

The number of elements per transition or tween. See details

ease

The easing function to use for each transition or tween. See details. Defaults to 'linear'

Value

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 functions.

Details

tween and 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 function.

tween_numeric will provide a linear interpolation between the points based on the sequence returned by the easing function. tween_date and tween_datetime 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 n and ease arguments differs somewhat between the standard and *_t versions of the functions. In the standard function n and ease refers to the length and easing function of each transition, being recycled if necessary to length(data) - 1. In the *_t functions n and 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 length(data).

Difference Between tween_numeric and approx()

tween_numeric (and 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 for tween_numeric. Apart from that tween_numeric of course supports easing functions and is vectorized.

Examples

tween_numeric(list(1:3, 10:8, c(20, 60, 30)), 10)
#> [[1]]
#>  [1]  1.00000  2.00000  3.00000  4.00000  5.00000  6.00000  7.00000  8.00000
#>  [9]  9.00000 10.00000 11.11111 12.22222 13.33333 14.44444 15.55556 16.66667
#> [17] 17.77778 18.88889 20.00000
#> 
#> [[2]]
#>  [1]  2.000000  2.777778  3.555556  4.333333  5.111111  5.888889  6.666667
#>  [8]  7.444444  8.222222  9.000000 14.666667 20.333333 26.000000 31.666667
#> [15] 37.333333 43.000000 48.666667 54.333333 60.000000
#> 
#> [[3]]
#>  [1]  3.000000  3.555556  4.111111  4.666667  5.222222  5.777778  6.333333
#>  [8]  6.888889  7.444444  8.000000 10.444444 12.888889 15.333333 17.777778
#> [15] 20.222222 22.666667 25.111111 27.555556 30.000000
#> 

tween_colour_t(list(colours()[1:4], colours()[1:2], colours()[25:100]), 100)
#> [[1]]
#>   [1] "#FFFFFF" "#FFFFFF" "#FEFFFF" "#FEFEFF" "#FDFEFF" "#FDFEFF" "#FCFEFF"
#>   [8] "#FCFEFF" "#FBFDFF" "#FBFDFF" "#FAFDFF" "#FAFDFF" "#FAFCFF" "#F9FCFF"
#>  [15] "#F9FCFF" "#F8FCFF" "#F8FCFF" "#F7FBFF" "#F7FBFF" "#F6FBFF" "#F6FBFF"
#>  [22] "#F5FBFF" "#F5FAFF" "#F5FAFF" "#F4FAFF" "#F4FAFF" "#F3F9FF" "#F3F9FF"
#>  [29] "#F2F9FF" "#F2F9FF" "#F1F9FF" "#F1F8FF" "#F0F8FF" "#F0F8FF" "#F0F8FE"
#>  [36] "#F1F7FD" "#F1F7FB" "#F1F6FA" "#F2F6F9" "#F2F6F8" "#F3F5F6" "#F3F5F5"
#>  [43] "#F3F4F4" "#F4F4F3" "#F4F4F2" "#F4F3F0" "#F4F3EF" "#F5F2EE" "#F5F2ED"
#>  [50] "#F5F2EC" "#F6F1EA" "#F6F1E9" "#F6F0E8" "#F7F0E7" "#F7F0E5" "#F7EFE4"
#>  [57] "#F7EFE3" "#F8EFE2" "#F8EEE1" "#F8EEDF" "#F9EDDE" "#F9EDDD" "#F9EDDC"
#>  [64] "#F9ECDB" "#FAECD9" "#FAEBD8" "#FAEBD7" "#FAEBD7" "#FAEBD7" "#FAEBD7"
#>  [71] "#FBEBD7" "#FBECD8" "#FBECD8" "#FBECD8" "#FBECD8" "#FBECD8" "#FCECD8"
#>  [78] "#FCECD8" "#FCECD8" "#FCEDD9" "#FCEDD9" "#FCEDD9" "#FCEDD9" "#FDEDD9"
#>  [85] "#FDEDD9" "#FDEDD9" "#FDEDD9" "#FDEEDA" "#FDEEDA" "#FDEEDA" "#FEEEDA"
#>  [92] "#FEEEDA" "#FEEEDA" "#FEEEDA" "#FEEEDA" "#FEEFDB" "#FFEFDB" "#FFEFDB"
#>  [99] "#FFEFDB" "#FFEFDB"
#> 
#> [[2]]
#>   [1] "#FFFFFF" "#FFFFFF" "#FFFFFF" "#FFFFFF" "#FEFFFF" "#FEFFFF" "#FEFFFF"
#>   [8] "#FEFFFF" "#FEFEFF" "#FEFEFF" "#FDFEFF" "#FDFEFF" "#FDFEFF" "#FDFEFF"
#>  [15] "#FDFEFF" "#FDFEFF" "#FDFEFF" "#FCFEFF" "#FCFEFF" "#FCFEFF" "#FCFEFF"
#>  [22] "#FCFEFF" "#FCFDFF" "#FCFDFF" "#FBFDFF" "#FBFDFF" "#FBFDFF" "#FBFDFF"
#>  [29] "#FBFDFF" "#FBFDFF" "#FAFDFF" "#FAFDFF" "#FAFDFF" "#FAFDFF" "#FAFDFF"
#>  [36] "#FAFDFF" "#FAFCFF" "#F9FCFF" "#F9FCFF" "#F9FCFF" "#F9FCFF" "#F9FCFF"
#>  [43] "#F9FCFF" "#F9FCFF" "#F8FCFF" "#F8FCFF" "#F8FCFF" "#F8FCFF" "#F8FCFF"
#>  [50] "#F8FCFF" "#F7FBFF" "#F7FBFF" "#F7FBFF" "#F7FBFF" "#F7FBFF" "#F7FBFF"
#>  [57] "#F7FBFF" "#F6FBFF" "#F6FBFF" "#F6FBFF" "#F6FBFF" "#F6FBFF" "#F6FBFF"
#>  [64] "#F5FBFF" "#F5FAFF" "#F5FAFF" "#F5FAFF" "#F5FAFF" "#F5FAFF" "#F5FAFF"
#>  [71] "#F4FAFF" "#F4FAFF" "#F4FAFF" "#F4FAFF" "#F4FAFF" "#F4FAFF" "#F4FAFF"
#>  [78] "#F3FAFF" "#F3F9FF" "#F3F9FF" "#F3F9FF" "#F3F9FF" "#F3F9FF" "#F2F9FF"
#>  [85] "#F2F9FF" "#F2F9FF" "#F2F9FF" "#F2F9FF" "#F2F9FF" "#F2F9FF" "#F1F9FF"
#>  [92] "#F1F9FF" "#F1F8FF" "#F1F8FF" "#F1F8FF" "#F1F8FF" "#F0F8FF" "#F0F8FF"
#>  [99] "#F0F8FF" "#F0F8FF"
#> 
#> [[3]]
#>   [1] "#FFEBCD" "#B781EA" "#0000FF" "#0000FF" "#0000FF" "#0000F6" "#0000EE"
#>   [8] "#0000DD" "#0000CD" "#0000AB" "#00008B" "#5213B6" "#8A2BE2" "#A72583"
#>  [15] "#A52A2A" "#D13535" "#FF4040" "#F63D3D" "#EE3B3B" "#DD3737" "#CD3333"
#>  [22] "#AB2B2B" "#8B2323" "#B77052" "#DEB887" "#EEC591" "#FFD39B" "#F6CC96"
#>  [29] "#EEC591" "#DDB787" "#CDAA7D" "#AB8E69" "#8B7355" "#7C897A" "#5F9EA0"
#>  [36] "#7BC9CE" "#98F5FF" "#93EDF6" "#8EE5EE" "#84D5DD" "#7AC5CD" "#66A5AB"
#>  [43] "#53868B" "#73C165" "#7FFF00" "#7FFF00" "#7FFF00" "#7AF600" "#76EE00"
#>  [50] "#66CD00" "#458B00" "#D2691E" "#FF7F24" "#EE7621" "#CD661D" "#8B4513"
#>  [57] "#FF7F50" "#FF7256" "#EE6A50" "#CD5B45" "#8B3E2F" "#6495ED" "#FFF8DC"
#>  [64] "#FFF8DC" "#EEE8CD" "#CDC8B1" "#8B8878" "#00FFFF" "#00FFFF" "#00EEEE"
#>  [71] "#00CDCD" "#008B8B" "#00008B" "#008B8B" "#B8860B" "#FFB90F" "#EEAD0E"
#>  [78] "#CD950C" "#8B6508" "#A9A9A9" "#006400" "#A9A9A9" "#BDB76B" "#8B008B"
#>  [85] "#556B2F" "#CAFF70" "#BCEE68" "#A2CD5A" "#6E8B3D" "#FF8C00" "#FF7F00"
#>  [92] "#EE7600" "#CD6600" "#8B4500" "#9932CC" "#BF3EFF" "#B23AEE" "#9A32CD"
#>  [99] "#68228B" "#8B0000"
#>