Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Speed Up gganimate Rendering

I am currently creating a gif which contains large data. I want it in high resolution.

On my old PC it took hours to render and simply wasn't worth it.

My new PC has a very strong intel i9-9900k core processor which has sped it up to about 30 minutes but R only uses 1 core by default... I have 8 available and it would be great if I could just use them to get the rendering done in under 5 minutes. I will be needing to run this multiple times a week so it would be amazing to be able to use all 8 cores.

Is there anyway to take advantage of this? I know you can use multi-threading in some R code but I can't figure it out with ggplot2/gganimate.

I also have a strong graphics card if that can be used in any way to speed this up.

Or if there is any other way to speed it up that you can think of, even if it means changing package or even programming language that would be great!

like image 333
user3456588 Avatar asked Aug 09 '19 07:08

user3456588


1 Answers

As Roman pointed out in the comments, there is a pull request to facilitate parallell processing of animated ggplots.

Here is an example with a benchmark, from this GitHub comment

library(gganimate)  anim <- ggplot(mtcars, aes(mpg, disp)) +   transition_states(gear, transition_length = 2, state_length = 1) +   enter_fade() +   exit_fade()  future::plan("sequential")  ## default t0 <- system.time(animate(anim)) print(t0)  future::plan("multiprocess", workers = 4L) t1 <- system.time(animate(anim)) print(t1)  print(t0 / t1) ##      user    system   elapsed  ## 2.2802385 0.9121339 2.5819751 

The pull request has yet to be merged, but if you need this now you can install that particular fork with devtools::install_github()

This is much easier than what has previously been pointed out

like image 95
mhovd Avatar answered Sep 17 '22 13:09

mhovd