【发布时间】:2018-08-07 23:25:34
【问题描述】:
我有一些通过gganimate 动画的ggplot 对象,我想改变动画的速度。
这是来自 github 存储库的可重现示例:https://github.com/dgrtwo/gganimate
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)
此动画全程循环播放大约需要 12 秒。我怎样才能让它在 6 秒内完成循环?
我尝试将time 设置为不同的值,但无济于事,并且从帮助页面中也不清楚。
gganimate(p, time = 0.1)
更新
interval 似乎通常可以工作,但我仍然不清楚如何在 Rmarkdown 报告中完成这项工作。例如,如果我将下面的代码放在名为test.R 的文件中,然后运行rmarkdown::render('test.R'),我的动画将以默认速度运行,而不是预期的增加速度。我将如何在rmarkdown::render 的背景下完成这项工作?从这里看,我一直在尝试各种事情:https://github.com/dgrtwo/gganimate/commit/3aa2064cdfff30feb2b00724ad757fd5a5a62621,但无济于事。
knitr::opts_chunk$set(message = FALSE, warning = FALSE, fig.show = 'animate')
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)
capture.output(gganimate(p, interval = 0.2))
【问题讨论】:
-
在the README 的末尾,你需要设置
interval块选项,例如{r my-animation, interval = 1/60}
标签: r ggplot2 r-markdown gganimate