Search code examples
ranimationggplot2gganimate

How to set the speed of the animation in R?


I have set up an animation using gganimate in R. This animation is just too fast. How to set the speed of the frames?

Also the points disappears when showing the next dot. Is it possible that the points are show one by one so at the end I have a full scatter plot?

How can I fix this?

This is the testdata and my code so far:

#Test data
ID  Weight  Color Time
A   27  Red 1
A   11  Red 2
A   37  Red 3
A   49  Red 4
A   10  Red 5
A   25  Blue 6
A   49  Blue 7
A   20  Blue 8
A   21  Blue 9
A   36  Blue 10
A   24  Green 11
A   32  Green 12
A   47  Green 13
A   35  Green 14
A   24  Green 15
A   49  Yellow 16
A   42  Yellow 17
A   39  Yellow 18
A   22  Yellow 19
A   47  Yellow 20

#R code
library(plyr)
library(tidyr)
library(dplyr)
library(ggplot2)
library(gganimate)

p <- ggplot(dataset, aes(x=Color, y=Weight)) + geom_point()

order <- as.numeric(dataset$Time)

p + 
transition_time(order) +
labs(title = "TIME: {frame_time}") + enter_fade()

Solution

  • Possible duplicate of: Control speed of a gganimation

    In any case, I think this does what you want, if you play around with the fps argument a litte:

    p <- ggplot(dataset, aes(x=Color, y=Weight)) + geom_point()
    
    order <- as.numeric(dataset$Time)
    
    gif <- p + 
      transition_time(order) +
      labs(title = "TIME: {frame_time}") + enter_fade()
    animate(gif, fps = 2)