Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Define size for .gif created by gganimate - change dimension / resolution

Tags:

I'm using gganimate to create some .gif files that I want to insert into my reports. I'm able to save the files and view them fine, however, I find that the displayed size is small: 480x480. Is there a way to adjust that - perhaps along the lines of height and width arguments in ggsave()?

I can zoom in but that impacts the quality poorly and makes it rather unreadable for my use case.

Here's some sample code:

gplot <-    ggplot(gapminder,           aes(x = gdpPercap, y = lifeExp, colour = continent,               size = pop,               frame = year)) +     geom_point(alpha = 0.6) +      scale_x_log10()  gganimate(gplot, "test.gif") 

Below is the output for this code.

test.gif

like image 589
Gautam Avatar asked Mar 01 '18 20:03

Gautam


1 Answers

There can be issues with using the magick package.

I think a better solution is use the animate() function in gganimate to create an object which is then passed to the anim_save() function. No need to use another package.

library(gganimate) library(gapminder)  my.animation <-    ggplot(   gapminder,   aes(x = gdpPercap, y = lifeExp, colour = continent, size = pop)  ) + geom_point(alpha = 0.6) + scale_x_log10() + transition_time(year)  # animate in a two step process: animate(my.animation, height = 800, width =800) anim_save("Gapminder_example.gif") 
like image 78
Nathan Avatar answered Oct 11 '22 21:10

Nathan