使用gg_animate创建gif [英] Using gg_animate to create a gif

查看:97
本文介绍了使用gg_animate创建gif的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以在R中实现gg_animate来生成gif.我已经创建了ggmap,并将其另存为PDF.我想创建一个动画,可以在这些地图上滚动,可能会在每个图像上保持1或2秒钟.在R中有没有办法做到这一点,或者我应该使用某种gif创建器-如果可以的话,是否有建议?

Is there a way to implement gg_animate in R to produce a gif. I already have my ggmaps created and saved as PDFs. I would like to create an animation which scrolls through those maps maybe holding on each image for 1 or 2 seconds. Is there a way to do this in R or should I use some sort of gif creator - if so any suggestions?

非常感谢

推荐答案

更新Jul2018 :gganimate()经历了重写,现在已大大改进.以前的API仅在存档版本中可用,不应与新版本一起使用.

Update Jul2018: gganimate() has undergone a rewrite and is now much improved. The previous API is only available through the archived version and should not be expected to work with the new version.

使用新版本:

library(gapminder)
library(gganimate)

## standard ggplot2
ggplot(gapminder, aes(gdpPercap, lifeExp, size = pop, colour = country)) +
  geom_point(alpha = 0.7, show.legend = FALSE) +
  scale_colour_manual(values = country_colors) +
  scale_size(range = c(2, 12)) +
  scale_x_log10() +
  # Here comes the gganimate specific bits
  labs(title = 'Year: {frame_time}', x = 'GDP per capita', y = 'life expectancy') +
  transition_time(year) +
  ease_aes('linear')

制作更加流畅的图形

原始答案:

我发现 gganimate 软件包在此方面做得很好.

I found the gganimate package to do quite well at this.

library(gapminder)
library(ggplot2)
theme_set(theme_bw())
p <- ggplot(gapminder, aes(gdpPercap, lifeExp, size = pop, color = continent, frame = year)) +
  geom_point() +
  scale_x_log10()

library(gganimate)

gganimate(p)

gganimate(p, "output.gif")

更新2016年12月:gganimate()现在替换gg_animate()并将cowplot作为依赖项(一旦

Update Dec2016: gganimate() now replaces gg_animate() and adds cowplot as a dependency (should auto-install once Issue #32 is resolved).

这篇关于使用gg_animate创建gif的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆