我正在尝试学习如何用gganimate动画情节,我想知道是否有人对我遇到的问题有什么建议。为了简单起见,我在RStudio云中创建了一个新项目,安装了ggplot2、gganimate和datasauRus包,并遵循了艾萨克·费伯中的示例
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图像对象的相同错误),并且当我尝试以下代码时:
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方法的示例或文档。如果有人在这个话题上有任何建议,我们将不胜感激!
发布于 2019-11-21 18:09:11
你做得太多了:
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)

发布于 2020-03-20 04:07:15
我通过在gifski_renderer()中指定animate()来解决这个问题。
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()的默认呈现程序,但需要显式指定。第一次做完之后,我不再需要设置它,这是我无法解释的行为。
https://stackoverflow.com/questions/58980115
复制相似问题