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
#> 139 -0.50000000 0.43278817 0.08183302 0.095850352  15  enter      1
#> 140 -0.43570567 0.43278817 0.08183302 0.095850352  15  enter      2
#> 1   -0.50000000 0.65832223 0.12811576 0.046808935   1  enter      3
#> 21  -0.50000000 0.91833784 0.12901623 0.033095370   3  enter      3
#> 141  0.01435464 0.43278817 0.08183302 0.095850352  15  enter      3
#> 159 -0.50000000 0.61601443 0.12666658 0.092628333  17  enter      3
#> 2   -0.41369168 0.65832223 0.12811576 0.046808935   1  enter      4
#> 22  -0.44383626 0.91833784 0.12901623 0.033095370   3  enter      4
#> 142  0.46441494 0.43278817 0.08183302 0.095850352  15  enter      4
#> 160 -0.40729582 0.61601443 0.12666658 0.092628333  17  enter      4
#> 3    0.19046655 0.65832223 0.12811576 0.046808935   1  enter      5
#> 23  -0.05069009 0.91833784 0.12901623 0.033095370   3  enter      5
#> 143  0.52870927 0.43278817 0.08183302 0.095850352  15 static      5
#> 161  0.24163343 0.61601443 0.12666658 0.092628333  17  enter      5
#> 4    0.79462478 0.65832223 0.12811576 0.046808935   1  enter      6
#> 24   0.34245608 0.91833784 0.12901623 0.033095370   3  enter      6
#> 144  0.52870927 0.43278817 0.08183302 0.095850352  15 static      6
#> 162  0.89056269 0.61601443 0.12666658 0.092628333  17  enter      6
#> 5    0.88093309 0.65832223 0.12811576 0.046808935   1 static      7
#> 25   0.39861982 0.91833784 0.12901623 0.033095370   3 static      7
#> 131 -0.50000000 0.60003734 0.22002471 0.006840642  14  enter      7
#> 145  0.52870927 0.43278817 0.08183302 0.095850352  15 static      7
#> 163  0.98326687 0.61601443 0.12666658 0.092628333  17 static      7
#> 6    0.88093309 0.65832223 0.12811576 0.046808935   1 static      8
#> 26   0.39861982 0.91833784 0.12901623 0.033095370   3 static      8
#> 50  -0.50000000 0.20123842 0.24177609 0.088801518   6  enter      8
#> 132 -0.42805509 0.60003734 0.22002471 0.006840642  14  enter      8
#> 146  0.52870927 0.43278817 0.08183302 0.095850352  15 static      8
#> 164  0.98326687 0.61601443 0.12666658 0.092628333  17 static      8
#> 7    0.88093309 0.65832223 0.12811576 0.046808935   1    raw      9
#> 27   0.39861982 0.91833784 0.12901623 0.033095370   3    raw      9
#> 51  -0.44055498 0.20123842 0.24177609 0.088801518   6  enter      9
#> 133  0.07555932 0.60003734 0.22002471 0.006840642  14  enter      9
#> 147  0.52870927 0.43278817 0.08183302 0.095850352  15 static      9
#> 165  0.98326687 0.61601443 0.12666658 0.092628333  17 static      9
#> 8    0.97264671 0.65832223 0.12811576 0.046808935   1   exit     10
#> 28   0.94930991 0.91833784 0.12901623 0.033095370   3   exit     10
#> 52  -0.02443984 0.20123842 0.24177609 0.088801518   6  enter     10
#> 134  0.57917372 0.60003734 0.22002471 0.006840642  14  enter     10
#> 148  0.52870927 0.43278817 0.08183302 0.095850352  15    raw     10
#> 166  0.98326687 0.61601443 0.12666658 0.092628333  17 static     10
#> 9    1.40828638 0.65832223 0.12811576 0.046808935   1   exit     11
#> 29   1.50000000 0.91833784 0.12901623 0.033095370   3   exit     11
#> 53   0.39167531 0.20123842 0.24177609 0.088801518   6  enter     11
#> 135  0.65111864 0.60003734 0.22002471 0.006840642  14 static     11
#> 149  1.01435464 0.43278817 0.08183302 0.095850352  15   exit     11
#> 167  0.98326687 0.61601443 0.12666658 0.092628333  17    raw     11
#> 10   1.50000000 0.65832223 0.12811576 0.046808935   1   exit     12
#> 54   0.45112033 0.20123842 0.24177609 0.088801518   6 static     12
#> 136  0.65111864 0.60003734 0.22002471 0.006840642  14    raw     12
#> 150  1.50000000 0.43278817 0.08183302 0.095850352  15   exit     12
#> 168  1.05981993 0.61601443 0.12666658 0.092628333  17   exit     12
#> 55   0.45112033 0.20123842 0.24177609 0.088801518   6 static     13
#> 110 -0.50000000 0.79537771 0.35418673 0.067769852  12  enter     13
#> 137  1.07555932 0.60003734 0.22002471 0.006840642  14   exit     13
#> 169  1.42344694 0.61601443 0.12666658 0.092628333  17   exit     13
#> 56   0.45112033 0.20123842 0.24177609 0.088801518   6 static     14
#> 111 -0.46021071 0.79537771 0.35418673 0.067769852  12  enter     14
#> 138  1.50000000 0.60003734 0.22002471 0.006840642  14   exit     14
#> 151 -0.50000000 0.92027580 0.36923607 0.024448352  16  enter     14
#> 170  1.50000000 0.61601443 0.12666658 0.092628333  17   exit     14
#> 57   0.45112033 0.20123842 0.24177609 0.088801518   6 static     15
#> 80  -0.50000000 0.85363587 0.40736135 0.028131306   9  enter     15
#> 112 -0.18168571 0.79537771 0.35418673 0.067769852  12  enter     15
#> 152 -0.45468029 0.92027580 0.36923607 0.024448352  16  enter     15
#> 58   0.45112033 0.20123842 0.24177609 0.088801518   6    raw     16
#> 81  -0.46024556 0.85363587 0.40736135 0.028131306   9  enter     16
#> 113  0.09683930 0.79537771 0.35418673 0.067769852  12  enter     16
#> 153 -0.13744231 0.92027580 0.36923607 0.024448352  16  enter     16
#> 59   0.97556016 0.20123842 0.24177609 0.088801518   6   exit     17
#> 82  -0.18196450 0.85363587 0.40736135 0.028131306   9  enter     17
#> 114  0.13662858 0.79537771 0.35418673 0.067769852  12 static     17
#> 120 -0.50000000 0.88655051 0.45584015 0.070071499  13  enter     17
#> 154  0.17979568 0.92027580 0.36923607 0.024448352  16  enter     17
#> 60   1.50000000 0.20123842 0.24177609 0.088801518   6   exit     18
#> 83   0.42429068 0.85363587 0.40736135 0.028131306   9  enter     18
#> 115  0.13662858 0.79537771 0.35418673 0.067769852  12 static     18
#> 121 -0.45423253 0.88655051 0.45584015 0.070071499  13  enter     18
#> 155  0.22511539 0.92027580 0.36923607 0.024448352  16 static     18
#> 84   0.70257174 0.85363587 0.40736135 0.028131306   9  enter     19
#> 116  0.13662858 0.79537771 0.35418673 0.067769852  12 static     19
#> 122 -0.13386022 0.88655051 0.45584015 0.070071499  13  enter     19
#> 156  0.22511539 0.92027580 0.36923607 0.024448352  16    raw     19
#> 30  -0.50000000 0.14871035 0.51096488 0.062868211   4  enter     20
#> 85   0.74232618 0.85363587 0.40736135 0.028131306   9 static     20
#> 89  -0.50000000 0.80341257 0.51474456 0.070694650  10  enter     20
#> 117  0.13662858 0.79537771 0.35418673 0.067769852  12    raw     20
#> 123  0.56409372 0.88655051 0.45584015 0.070071499  13  enter     20
#> 157  0.86255769 0.92027580 0.36923607 0.024448352  16   exit     20
#> 11  -0.50000000 0.25920274 0.53863312 0.053819245   2  enter     21
#> 31  -0.44184246 0.14871035 0.51096488 0.062868211   4  enter     21
#> 40  -0.50000000 0.64068048 0.54379269 0.045255247   5  enter     21
#> 86   0.74232618 0.85363587 0.40736135 0.028131306   9    raw     21
#> 90  -0.43442371 0.80341257 0.51474456 0.070694650  10  enter     21
#> 118  0.81831429 0.79537771 0.35418673 0.067769852  12   exit     21
#> 124  0.88446602 0.88655051 0.45584015 0.070071499  13  enter     21
#> 158  1.50000000 0.92027580 0.36923607 0.024448352  16   exit     21
#> 12  -0.42304818 0.25920274 0.53863312 0.053819245   2  enter     22
#> 32  -0.03473967 0.14871035 0.51096488 0.062868211   4  enter     22
#> 41  -0.47934696 0.64068048 0.54379269 0.045255247   5  enter     22
#> 87   1.12116309 0.85363587 0.40736135 0.028131306   9   exit     22
#> 91   0.02461035 0.80341257 0.51474456 0.070694650  10  enter     22
#> 119  1.50000000 0.79537771 0.35418673 0.067769852  12   exit     22
#> 125  0.93023350 0.88655051 0.45584015 0.070071499  13 static     22
#> 13   0.11561458 0.25920274 0.53863312 0.053819245   2  enter     23
#> 33   0.37236311 0.14871035 0.51096488 0.062868211   4  enter     23
#> 42  -0.33477572 0.64068048 0.54379269 0.045255247   5  enter     23
#> 88   1.50000000 0.85363587 0.40736135 0.028131306   9   exit     23
#> 92   0.48364441 0.80341257 0.51474456 0.070694650  10  enter     23
#> 126  0.93023350 0.88655051 0.45584015 0.070071499  13 static     23
#> 14   0.65427733 0.25920274 0.53863312 0.053819245   2  enter     24
#> 34   0.43052065 0.14871035 0.51096488 0.062868211   4 static     24
#> 43  -0.01981693 0.64068048 0.54379269 0.045255247   5  enter     24
#> 93   0.54922071 0.80341257 0.51474456 0.070694650  10 static     24
#> 127  0.93023350 0.88655051 0.45584015 0.070071499  13 static     24
#> 15   0.73122915 0.25920274 0.53863312 0.053819245   2 static     25
#> 35   0.43052065 0.14871035 0.51096488 0.062868211   4 static     25
#> 44   0.12475431 0.64068048 0.54379269 0.045255247   5  enter     25
#> 94   0.54922071 0.80341257 0.51474456 0.070694650  10 static     25
#> 128  0.93023350 0.88655051 0.45584015 0.070071499  13    raw     25
#> 16   0.73122915 0.25920274 0.53863312 0.053819245   2 static     26
#> 36   0.43052065 0.14871035 0.51096488 0.062868211   4 static     26
#> 45   0.14540735 0.64068048 0.54379269 0.045255247   5 static     26
#> 95   0.54922071 0.80341257 0.51474456 0.070694650  10 static     26
#> 129  1.21511675 0.88655051 0.45584015 0.070071499  13   exit     26
#> 17   0.73122915 0.25920274 0.53863312 0.053819245   2 static     27
#> 37   0.43052065 0.14871035 0.51096488 0.062868211   4    raw     27
#> 46   0.14540735 0.64068048 0.54379269 0.045255247   5 static     27
#> 96   0.54922071 0.80341257 0.51474456 0.070694650  10    raw     27
#> 130  1.50000000 0.88655051 0.45584015 0.070071499  13   exit     27
#> 193 -0.50000000 0.76901352 0.66867450 0.043879963  20  enter     27
#> 18   0.73122915 0.25920274 0.53863312 0.053819245   2    raw     28
#> 38   0.96526033 0.14871035 0.51096488 0.062868211   4   exit     28
#> 47   0.14540735 0.64068048 0.54379269 0.045255247   5    raw     28
#> 97   0.69007690 0.80341257 0.51474456 0.070694650  10   exit     28
#> 194 -0.42014716 0.76901352 0.66867450 0.043879963  20  enter     28
#> 19   1.11561458 0.25920274 0.53863312 0.053819245   2   exit     29
#> 39   1.50000000 0.14871035 0.51096488 0.062868211   4   exit     29
#> 48   0.82270367 0.64068048 0.54379269 0.045255247   5   exit     29
#> 98   1.35914381 0.80341257 0.51474456 0.070694650  10   exit     29
#> 195  0.13882275 0.76901352 0.66867450 0.043879963  20  enter     29
#> 20   1.50000000 0.25920274 0.53863312 0.053819245   2   exit     30
#> 49   1.50000000 0.64068048 0.54379269 0.045255247   5   exit     30
#> 99   1.50000000 0.80341257 0.51474456 0.070694650  10   exit     30
#> 171 -0.50000000 0.43571816 0.73987251 0.050274708  18  enter     30
#> 196  0.69779266 0.76901352 0.66867450 0.043879963  20  enter     30
#> 172 -0.46193445 0.43571816 0.73987251 0.050274708  18  enter     31
#> 197  0.77764551 0.76901352 0.66867450 0.043879963  20 static     31
#> 173 -0.19547561 0.43571816 0.73987251 0.050274708  18  enter     32
#> 198  0.77764551 0.76901352 0.66867450 0.043879963  20 static     32
#> 61  -0.50000000 0.74362132 0.80314412 0.078420182   7  enter     33
#> 174  0.07098324 0.43571816 0.73987251 0.050274708  18  enter     33
#> 199  0.77764551 0.76901352 0.66867450 0.043879963  20    raw     33
#> 62  -0.43257616 0.74362132 0.80314412 0.078420182   7  enter     34
#> 175  0.10904879 0.43571816 0.73987251 0.050274708  18 static     34
#> 200  1.13882275 0.76901352 0.66867450 0.043879963  20   exit     34
#> 63   0.03939075 0.74362132 0.80314412 0.078420182   7  enter     35
#> 176  0.10904879 0.43571816 0.73987251 0.050274708  18 static     35
#> 201  1.50000000 0.76901352 0.66867450 0.043879963  20   exit     35
#> 64   0.51135765 0.74362132 0.80314412 0.078420182   7  enter     36
#> 177  0.10904879 0.43571816 0.73987251 0.050274708  18    raw     36
#> 65   0.57878149 0.74362132 0.80314412 0.078420182   7 static     37
#> 178  0.31511563 0.43571816 0.73987251 0.050274708  18   exit     37
#> 66   0.57878149 0.74362132 0.80314412 0.078420182   7 static     38
#> 179  1.29393315 0.43571816 0.73987251 0.050274708  18   exit     38
#> 67   0.57878149 0.74362132 0.80314412 0.078420182   7 static     39
#> 72  -0.50000000 0.84763743 0.94791372 0.013805955   8  enter     39
#> 180  1.50000000 0.43571816 0.73987251 0.050274708  18   exit     39
#> 181 -0.50000000 0.89730441 0.95586629 0.093551714  19  enter     39
#> 68   0.57878149 0.74362132 0.80314412 0.078420182   7    raw     40
#> 73  -0.46434893 0.84763743 0.94791372 0.013805955   8  enter     40
#> 100 -0.50000000 0.02387676 0.98154185 0.044218692  11  enter     40
#> 182 -0.48176174 0.89730441 0.95586629 0.093551714  19  enter     40
#> 69   0.71525831 0.74362132 0.80314412 0.078420182   7   exit     41
#> 74  -0.21479144 0.84763743 0.94791372 0.013805955   8  enter     41
#> 101 -0.46369458 0.02387676 0.98154185 0.044218692  11  enter     41
#> 183 -0.35409395 0.89730441 0.95586629 0.093551714  19  enter     41
#> 70   1.36352318 0.74362132 0.80314412 0.078420182   7   exit     42
#> 75   0.03476605 0.84763743 0.94791372 0.013805955   8  enter     42
#> 102 -0.20955667 0.02387676 0.98154185 0.044218692  11  enter     42
#> 184 -0.07596054 0.89730441 0.95586629 0.093551714  19  enter     42
#> 71   1.50000000 0.74362132 0.80314412 0.078420182   7   exit     43
#> 76   0.07041712 0.84763743 0.94791372 0.013805955   8 static     43
#> 103  0.34410094 0.02387676 0.98154185 0.044218692  11  enter     43
#> 185  0.05170726 0.89730441 0.95586629 0.093551714  19  enter     43
#> 77   0.07041712 0.84763743 0.94791372 0.013805955   8    raw     44
#> 104  0.59823886 0.02387676 0.98154185 0.044218692  11  enter     44
#> 186  0.06994552 0.89730441 0.95586629 0.093551714  19 static     44
#> 78   0.78520856 0.84763743 0.94791372 0.013805955   8   exit     45
#> 105  0.63454427 0.02387676 0.98154185 0.044218692  11 static     45
#> 187  0.06994552 0.89730441 0.95586629 0.093551714  19 static     45
#> 79   1.50000000 0.84763743 0.94791372 0.013805955   8   exit     46
#> 106  0.63454427 0.02387676 0.98154185 0.044218692  11 static     46
#> 188  0.06994552 0.89730441 0.95586629 0.093551714  19 static     46
#> 107  0.63454427 0.02387676 0.98154185 0.044218692  11    raw     47
#> 189  0.06994552 0.89730441 0.95586629 0.093551714  19 static     47
#> 108  1.06727214 0.02387676 0.98154185 0.044218692  11   exit     48
#> 190  0.06994552 0.89730441 0.95586629 0.093551714  19    raw     48
#> 109  1.50000000 0.02387676 0.98154185 0.044218692  11   exit     49
#> 191  0.78497276 0.89730441 0.95586629 0.093551714  19   exit     49
#> 192  1.50000000 0.89730441 0.95586629 0.093551714  19   exit     50