首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用gganimate和gganimate动画

用gganimate和gganimate动画
EN

Stack Overflow用户
提问于 2019-11-21 17:03:03
回答 2查看 1.4K关注 0票数 1

我正在尝试学习如何用gganimate动画情节,我想知道是否有人对我遇到的问题有什么建议。为了简单起见,我在RStudio云中创建了一个新项目,安装了ggplot2gganimatedatasauRus包,并遵循了艾萨克·费伯中的示例

代码语言:javascript
复制
library(datasauRus)
library(ggplot2)
library(gganimate)
ggplot(datasaurus_dozen, aes(x=x,y=y)) +
  geom_point() + 
  theme_minimal() + 
  transition_states(dataset,3,1) +
  ease_aes()

这会创建一系列.PNG文件,但我看不到动画。有些人似乎认为,我可以看到它使用“打印”函数,但这也不起作用。

我也无法将它导出为.GIF,尽管我遵循了给这里的建议。具体来说,magick包对我不起作用(我得到了关于我的图像不是magick图像对象的相同错误),并且当我尝试以下代码时:

代码语言:javascript
复制
p <- ggplot(datasaurus_dozen, aes(x=x,y=y)) +
  geom_point() + 
  theme_minimal() + 
  transition_states(dataset,3,1) +
  ease_aes()
anim <- animate(p)
anim_save("myfilename.gif",anim)

R告诉我

动画对象不指定save_animation方法。

我无法找到告诉我如何指定save_animation方法的示例或文档。如果有人在这个话题上有任何建议,我们将不胜感激!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-11-21 18:09:11

你做得太多了:

代码语言:javascript
复制
library(datasauRus) 
library(ggplot2) 
library(gganimate)

p <- ggplot(datasaurus_dozen, aes(x=x,y=y)) +
geom_point() +
theme_minimal() +
transition_states(dataset,3,1) + 
ease_aes() 

anim_save("myfilename.gif",p)

票数 1
EN

Stack Overflow用户

发布于 2020-03-20 04:07:15

我通过在gifski_renderer()中指定animate()来解决这个问题。

代码语言:javascript
复制
library(tidyverse)
library(gganimate)
library(gapminder)

g <- 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() +
  facet_wrap(~continent) +
  # Here comes the gganimate specific bits
  labs(title = 'Year: {frame_time}', x = 'GDP per capita', y = 'life expectancy') +
  transition_time(year) +
  ease_aes('linear')

animate(g, height=400, width=600, renderer=gifski_renderer())

anim_save("gapminder.gif", g)

注意:这是animate()的默认呈现程序,但需要显式指定。第一次做完之后,我不再需要设置它,这是我无法解释的行为。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58980115

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档