Reputation: 6884
I have a plot with several hundred lines. I would like these lines to appear over time; first slowly, to have the time to explain what's going on to the audience; then faster and faster.
The minimal example below gives an example of how the animation currently looks. What I want is that the first frame has a few seconds, the second is roughly half as long, the third another half of that, etc. Essentially, the duration should get exponentially smaller.
However, I cannot figure out how to change the duration. I thought that the option ease_aes()
should do it as it allows functions such as exponential_in
. Using this option though seems to change nothing for me.
I also found an SO post that slows one particular frame down, so I thought I should be able to apply this code to my use case. Again though, the transition duration looks identical across frames. (Note that the last example has the issue that the prior line disappears, which is also not want I want; it's just to illustrate though that the durations don't change).
What am I missing?
library(data.table)
library(gganimate)
DT <- data.table(x = rep(1:10, times=100),
y = rep(1:10, times=100) + rnorm(1000),
id = rep(1:100, each=10))
anim <- ggplot(DT) +
geom_line(aes(x=x, y=y, group=id)) +
transition_reveal(id)
animate(anim, nframes = 100)
####Playing around with eas_aes does not work for me
anim <- ggplot(DT) +
geom_line(aes(x=x, y=y, group=id)) +
transition_reveal(id) +
ease_aes("exponential-in")
animate(anim, nframes = 100)
####Transition states also doesn't work:
# https://stackoverflow.com/questions/66923904/how-to-make-the-transition-time-between-2-frames-longer-in-gganimate
anim <- ggplot(DT) +
geom_line(aes(x=x, y=y, group=id)) +
transition_states(id,
state_length = 0,
transition_length = 100:1)
animate(anim, nframes = 100)
Upvotes: 2
Views: 203
Reputation: 173858
Just create a time
column with an exponentially falling gap between successive times, and reveal according to that.
DT <- data.table(x = rep(1:10, times=100),
y = rep(1:10, times=100) + rnorm(1000),
id = rep(1:100, each=10),
time = rep(cumsum(100 / 1:100), each = 10))
anim <- ggplot(DT) +
geom_line(aes(x=x, y=y, group=id)) +
transition_reveal(time)
animate(anim, nframes = 200)
Upvotes: 3