Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Control speed of a gganimation

I want to slow the transition speed between states when using library(gganimate).

Here is a mini example:

# devtools::install_github("thomasp85/gganimate") library(gganimate) # v0.9.9.9999  dat_sim <- function(t_state, d_state) {   data.frame(     x = runif(1000, 0, 1),     y = runif(1000, 0, 1),     t_state = t_state*d_state     ) }  dat <- purrr::map_df(1:100, ~ dat_sim(., 1))  ggplot(dat, aes(x, y)) +   geom_hex(bins = 5) +   theme_void() +   lims(x = c(.3, .7),        y = c(.3, .7)) +   theme(legend.position = "none") +   transition_time(t_state) 

toofast

My ideal behavior would be much slower (10-100x), so color changes gradually evolve and nobody has a seizure.

If I try to use transition_states() for more manual control, I get a gif with mostly blank frames. I've tried various combinations for transition_legnth= and state_length= without a noticeable effect.

ggplot(dat, aes(x, y)) +   geom_hex(bins = 5) +   theme_void() +   lims(x = c(.3, .7),        y = c(.3, .7)) +   theme(legend.position = "none") +   transition_states(t_state, transition_length = .1, state_length = 2) 

mostlyblank

like image 620
Nate Avatar asked Sep 09 '18 12:09

Nate


People also ask

How do I reduce the speed of an animation in Canva?

To do this, click on the “Timeline” icon in the upper left corner of the Canva editor. This will open up a timeline of all of the different elements on your design. To change the speed of an animation, simply click and drag the element along the timeline. The further you drag it, the faster the animation will play.


1 Answers

I found in docs animate function which can take fps and detail parameters.

@param fps The frame rate of the animation in frames/sec

@param detail The number of additional frames to calculate, per frame

The result:

p <- ggplot(dat, aes(x, y)) +       geom_hex(bins = 5) +       theme_void() +       lims(x = c(.3, .7),            y = c(.3, .7)) +       theme(legend.position = "none") +       transition_time(t_state) animate(p, fps=1) 

enter image description here

Also there you can specify output format such as png, jpeg, svg.

like image 75
RobJan Avatar answered Sep 28 '22 01:09

RobJan