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.

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

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)
#>                x          y       time    duration .id .phase .frame
#> 146 -0.500000000 0.63454427 0.02387676 0.098154185  16  enter      1
#> 147 -0.461180695 0.63454427 0.02387676 0.098154185  16  enter      2
#> 32  -0.500000000 0.51680410 0.06994552 0.089730441   4  enter      3
#> 148 -0.189445560 0.63454427 0.02387676 0.098154185  16  enter      3
#> 33  -0.447223186 0.51680410 0.06994552 0.089730441   4  enter      4
#> 149  0.082289575 0.63454427 0.02387676 0.098154185  16  enter      4
#> 23  -0.500000000 0.45185844 0.10904879 0.043571816   3  enter      5
#> 34  -0.077785485 0.51680410 0.06994552 0.089730441   4  enter      5
#> 150  0.121108880 0.63454427 0.02387676 0.098154185  16 static      5
#> 24  -0.412631093 0.45185844 0.10904879 0.043571816   3  enter      6
#> 35   0.291652216 0.51680410 0.06994552 0.089730441   4  enter      6
#> 77  -0.500000000 0.43052065 0.14871035 0.051096488   9  enter      6
#> 151  0.121108880 0.63454427 0.02387676 0.098154185  16 static      6
#> 25   0.198951253 0.45185844 0.10904879 0.043571816   3  enter      7
#> 36   0.344429031 0.51680410 0.06994552 0.089730441   4 static      7
#> 78  -0.461684531 0.43052065 0.14871035 0.051096488   9  enter      7
#> 152  0.121108880 0.63454427 0.02387676 0.098154185  16 static      7
#> 26   0.810533599 0.45185844 0.10904879 0.043571816   3  enter      8
#> 37   0.344429031 0.51680410 0.06994552 0.089730441   4 static      8
#> 79  -0.193476250 0.43052065 0.14871035 0.051096488   9  enter      8
#> 96  -0.500000000 0.45112033 0.20123842 0.024177609  11  enter      8
#> 153  0.121108880 0.63454427 0.02387676 0.098154185  16 static      8
#> 1   -0.500000000 0.66589079 0.22511539 0.092027580   1  enter      9
#> 27   0.897902506 0.45185844 0.10904879 0.043571816   3 static      9
#> 38   0.344429031 0.51680410 0.06994552 0.089730441   4 static      9
#> 80   0.074732032 0.43052065 0.14871035 0.051096488   9  enter      9
#> 97  -0.463261351 0.45112033 0.20123842 0.024177609  11  enter      9
#> 154  0.121108880 0.63454427 0.02387676 0.098154185  16    raw      9
#> 2   -0.476393672 0.66589079 0.22511539 0.092027580   1  enter     10
#> 28   0.897902506 0.45185844 0.10904879 0.043571816   3 static     10
#> 39   0.344429031 0.51680410 0.06994552 0.089730441   4 static     10
#> 81   0.113047501 0.43052065 0.14871035 0.051096488   9 static     10
#> 98  -0.206090808 0.45112033 0.20123842 0.024177609  11  enter     10
#> 155  0.810554440 0.63454427 0.02387676 0.098154185  16   exit     10
#> 3   -0.311149379 0.66589079 0.22511539 0.092027580   1  enter     11
#> 29   0.897902506 0.45185844 0.10904879 0.043571816   3    raw     11
#> 40   0.344429031 0.51680410 0.06994552 0.089730441   4    raw     11
#> 60  -0.500000000 0.73122915 0.25920274 0.053863312   7  enter     11
#> 82   0.113047501 0.43052065 0.14871035 0.051096488   9 static     11
#> 99   0.354173590 0.45112033 0.20123842 0.024177609  11  enter     11
#> 156  1.500000000 0.63454427 0.02387676 0.098154185  16   exit     11
#> 4    0.048847117 0.66589079 0.22511539 0.092027580   1  enter     12
#> 30   1.198951253 0.45185844 0.10904879 0.043571816   3   exit     12
#> 41   0.922214515 0.51680410 0.06994552 0.089730441   4   exit     12
#> 61  -0.415472976 0.73122915 0.25920274 0.053863312   7  enter     12
#> 83   0.113047501 0.43052065 0.14871035 0.051096488   9 static     12
#> 100  0.611344133 0.45112033 0.20123842 0.024177609  11  enter     12
#> 5    0.214091410 0.66589079 0.22511539 0.092027580   1  enter     13
#> 31   1.500000000 0.45185844 0.10904879 0.043571816   3   exit     13
#> 42   1.500000000 0.51680410 0.06994552 0.089730441   4   exit     13
#> 62   0.176216188 0.73122915 0.25920274 0.053863312   7  enter     13
#> 84   0.113047501 0.43052065 0.14871035 0.051096488   9    raw     13
#> 101  0.648082782 0.45112033 0.20123842 0.024177609  11 static     13
#> 6    0.237697738 0.66589079 0.22511539 0.092027580   1 static     14
#> 63   0.767905353 0.73122915 0.25920274 0.053863312   7  enter     14
#> 85   0.806523750 0.43052065 0.14871035 0.051096488   9   exit     14
#> 102  0.648082782 0.45112033 0.20123842 0.024177609  11    raw     14
#> 7    0.237697738 0.66589079 0.22511539 0.092027580   1 static     15
#> 64   0.852432376 0.73122915 0.25920274 0.053863312   7 static     15
#> 86   1.500000000 0.43052065 0.14871035 0.051096488   9   exit     15
#> 103  1.074041391 0.45112033 0.20123842 0.024177609  11   exit     15
#> 8    0.237697738 0.66589079 0.22511539 0.092027580   1 static     16
#> 65   0.852432376 0.73122915 0.25920274 0.053863312   7 static     16
#> 104  1.500000000 0.45112033 0.20123842 0.024177609  11   exit     16
#> 9    0.237697738 0.66589079 0.22511539 0.092027580   1    raw     17
#> 66   0.852432376 0.73122915 0.25920274 0.053863312   7    raw     17
#> 10   0.424705480 0.66589079 0.22511539 0.092027580   1   exit     18
#> 67   1.176216188 0.73122915 0.25920274 0.053863312   7   exit     18
#> 183 -0.500000000 0.52870927 0.43278817 0.008183302  20  enter     18
#> 11   1.312992257 0.66589079 0.22511539 0.092027580   1   exit     19
#> 68   1.500000000 0.73122915 0.25920274 0.053863312   7   exit     19
#> 184 -0.466598173 0.52870927 0.43278817 0.008183302  20  enter     19
#> 12   1.500000000 0.66589079 0.22511539 0.092027580   1   exit     20
#> 185 -0.232785383 0.52870927 0.43278817 0.008183302  20  enter     20
#> 186  0.001027406 0.52870927 0.43278817 0.008183302  20  enter     21
#> 187  0.034429233 0.52870927 0.43278817 0.008183302  20 static     22
#> 188  0.034429233 0.52870927 0.43278817 0.008183302  20    raw     23
#> 189  0.767214617 0.52870927 0.43278817 0.008183302  20   exit     24
#> 175 -0.500000000 0.65111864 0.60003734 0.022002471  19  enter     25
#> 190  1.500000000 0.52870927 0.43278817 0.008183302  20   exit     25
#> 176 -0.430494826 0.65111864 0.60003734 0.022002471  19  enter     26
#> 87  -0.500000000 0.14540735 0.64068048 0.054379269  10  enter     27
#> 177  0.056041393 0.65111864 0.60003734 0.022002471  19  enter     27
#> 53  -0.500000000 0.88093309 0.65832223 0.012811576   6  enter     28
#> 88  -0.408108608 0.14540735 0.64068048 0.054379269  10  enter     28
#> 178  0.542577612 0.65111864 0.60003734 0.022002471  19  enter     28
#> 54  -0.423056022 0.88093309 0.65832223 0.012811576   6  enter     29
#> 89   0.235131140 0.14540735 0.64068048 0.054379269  10  enter     29
#> 179  0.612082787 0.65111864 0.60003734 0.022002471  19 static     29
#> 55   0.115551823 0.88093309 0.65832223 0.012811576   6  enter     30
#> 90   0.878370887 0.14540735 0.64068048 0.054379269  10  enter     30
#> 180  0.612082787 0.65111864 0.60003734 0.022002471  19    raw     30
#> 56   0.654159667 0.88093309 0.65832223 0.012811576   6  enter     31
#> 91   0.970262280 0.14540735 0.64068048 0.054379269  10 static     31
#> 105 -0.500000000 0.57878149 0.74362132 0.080314412  12  enter     31
#> 181  1.056041393 0.65111864 0.60003734 0.022002471  19   exit     31
#> 57   0.731103645 0.88093309 0.65832223 0.012811576   6    raw     32
#> 92   0.970262280 0.14540735 0.64068048 0.054379269  10 static     32
#> 106 -0.465245435 0.57878149 0.74362132 0.080314412  12  enter     32
#> 182  1.500000000 0.65111864 0.60003734 0.022002471  19   exit     32
#> 43  -0.500000000 0.67661080 0.77764551 0.076901352   5  enter     33
#> 58   1.115551823 0.88093309 0.65832223 0.012811576   6   exit     33
#> 93   0.970262280 0.14540735 0.64068048 0.054379269  10    raw     33
#> 107 -0.221963478 0.57878149 0.74362132 0.080314412  12  enter     33
#> 157 -0.500000000 0.13662858 0.79537771 0.035418673  17  enter     33
#> 44  -0.421196361 0.67661080 0.77764551 0.076901352   5  enter     34
#> 59   1.500000000 0.88093309 0.65832223 0.012811576   6   exit     34
#> 94   1.235131140 0.14540735 0.64068048 0.054379269  10   exit     34
#> 108  0.021318478 0.57878149 0.74362132 0.080314412  12  enter     34
#> 137 -0.500000000 0.54922071 0.80341257 0.051474456  15  enter     34
#> 158 -0.429411468 0.13662858 0.79537771 0.035418673  17  enter     34
#> 45   0.130429115 0.67661080 0.77764551 0.076901352   5  enter     35
#> 95   1.500000000 0.14540735 0.64068048 0.054379269  10   exit     35
#> 109  0.056073043 0.57878149 0.74362132 0.080314412  12 static     35
#> 116 -0.500000000 0.07041712 0.84763743 0.094791372  13  enter     35
#> 138 -0.430606274 0.54922071 0.80341257 0.051474456  15  enter     35
#> 159  0.064708254 0.13662858 0.79537771 0.035418673  17  enter     35
#> 46   0.682054590 0.67661080 0.77764551 0.076901352   5  enter     36
#> 110  0.056073043 0.57878149 0.74362132 0.080314412  12 static     36
#> 117 -0.468859613 0.07041712 0.84763743 0.094791372  13  enter     36
#> 128 -0.500000000 0.74232618 0.85363587 0.040736135  14  enter     36
#> 139  0.055149811 0.54922071 0.80341257 0.051474456  15  enter     36
#> 160  0.558827976 0.13662858 0.79537771 0.035418673  17  enter     36
#> 47   0.760858230 0.67661080 0.77764551 0.076901352   5 static     37
#> 111  0.056073043 0.57878149 0.74362132 0.080314412  12 static     37
#> 118 -0.250876903 0.07041712 0.84763743 0.094791372  13  enter     37
#> 129 -0.450335937 0.74232618 0.85363587 0.040736135  14  enter     37
#> 140  0.540905896 0.54922071 0.80341257 0.051474456  15  enter     37
#> 161  0.629416508 0.13662858 0.79537771 0.035418673  17 static     37
#> 166 -0.500000000 0.93023350 0.88655051 0.045584015  18  enter     37
#> 48   0.760858230 0.67661080 0.77764551 0.076901352   5 static     38
#> 69  -0.500000000 0.39861982 0.91833784 0.012901623   8  enter     38
#> 112  0.056073043 0.57878149 0.74362132 0.080314412  12 static     38
#> 119  0.224013999 0.07041712 0.84763743 0.094791372  13  enter     38
#> 130 -0.102687493 0.74232618 0.85363587 0.040736135  14  enter     38
#> 141  0.610299622 0.54922071 0.80341257 0.051474456  15 static     38
#> 162  0.629416508 0.13662858 0.79537771 0.035418673  17 static     38
#> 167 -0.424252794 0.93023350 0.88655051 0.045584015  18  enter     38
#> 49   0.760858230 0.67661080 0.77764551 0.076901352   5 static     39
#> 70  -0.452773823 0.39861982 0.91833784 0.012901623   8  enter     39
#> 113  0.056073043 0.57878149 0.74362132 0.080314412  12    raw     39
#> 120  0.441996709 0.07041712 0.84763743 0.094791372  13  enter     39
#> 131  0.244960950 0.74232618 0.85363587 0.040736135  14  enter     39
#> 142  0.610299622 0.54922071 0.80341257 0.051474456  15 static     39
#> 163  0.629416508 0.13662858 0.79537771 0.035418673  17    raw     39
#> 168  0.105977651 0.93023350 0.88655051 0.045584015  18  enter     39
#> 50   0.760858230 0.67661080 0.77764551 0.076901352   5    raw     40
#> 71  -0.122190582 0.39861982 0.91833784 0.012901623   8  enter     40
#> 114  0.778036522 0.57878149 0.74362132 0.080314412  12   exit     40
#> 121  0.473137096 0.07041712 0.84763743 0.094791372  13 static     40
#> 132  0.294625013 0.74232618 0.85363587 0.040736135  14 static     40
#> 143  0.610299622 0.54922071 0.80341257 0.051474456  15    raw     40
#> 164  1.064708254 0.13662858 0.79537771 0.035418673  17   exit     40
#> 169  0.636208096 0.93023350 0.88655051 0.045584015  18  enter     40
#> 13  -0.500000000 0.65296728 0.98326687 0.061601443   2  enter     41
#> 51   1.130429115 0.67661080 0.77764551 0.076901352   5   exit     41
#> 72   0.598008622 0.39861982 0.91833784 0.012901623   8  enter     41
#> 115  1.500000000 0.57878149 0.74362132 0.080314412  12   exit     41
#> 122  0.473137096 0.07041712 0.84763743 0.094791372  13 static     41
#> 133  0.294625013 0.74232618 0.85363587 0.040736135  14 static     41
#> 144  1.055149811 0.54922071 0.80341257 0.051474456  15   exit     41
#> 165  1.500000000 0.13662858 0.79537771 0.035418673  17   exit     41
#> 170  0.711955303 0.93023350 0.88655051 0.045584015  18 static     41
#> 14  -0.432585572 0.65296728 0.98326687 0.061601443   2  enter     42
#> 52   1.500000000 0.67661080 0.77764551 0.076901352   5   exit     42
#> 73   0.928591863 0.39861982 0.91833784 0.012901623   8  enter     42
#> 123  0.473137096 0.07041712 0.84763743 0.094791372  13 static     42
#> 134  0.294625013 0.74232618 0.85363587 0.040736135  14    raw     42
#> 145  1.500000000 0.54922071 0.80341257 0.051474456  15   exit     42
#> 171  0.711955303 0.93023350 0.88655051 0.045584015  18 static     42
#> 15   0.039315423 0.65296728 0.98326687 0.061601443   2  enter     43
#> 74   0.975818041 0.39861982 0.91833784 0.012901623   8    raw     43
#> 124  0.473137096 0.07041712 0.84763743 0.094791372  13 static     43
#> 135  0.897312507 0.74232618 0.85363587 0.040736135  14   exit     43
#> 172  0.711955303 0.93023350 0.88655051 0.045584015  18    raw     43
#> 16   0.511216418 0.65296728 0.98326687 0.061601443   2  enter     44
#> 75   1.237909020 0.39861982 0.91833784 0.012901623   8   exit     44
#> 125  0.473137096 0.07041712 0.84763743 0.094791372  13    raw     44
#> 136  1.500000000 0.74232618 0.85363587 0.040736135  14   exit     44
#> 173  1.105977651 0.93023350 0.88655051 0.045584015  18   exit     44
#> 17   0.578630846 0.65296728 0.98326687 0.061601443   2 static     45
#> 76   1.500000000 0.39861982 0.91833784 0.012901623   8   exit     45
#> 126  0.986568548 0.07041712 0.84763743 0.094791372  13   exit     45
#> 174  1.500000000 0.93023350 0.88655051 0.045584015  18   exit     45
#> 18   0.578630846 0.65296728 0.98326687 0.061601443   2 static     46
#> 127  1.500000000 0.07041712 0.84763743 0.094791372  13   exit     46
#> 19   0.578630846 0.65296728 0.98326687 0.061601443   2 static     47
#> 20   0.578630846 0.65296728 0.98326687 0.061601443   2    raw     48
#> 21   1.039315423 0.65296728 0.98326687 0.061601443   2   exit     49
#> 22   1.500000000 0.65296728 0.98326687 0.061601443   2   exit     50