我有一些通过 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 秒内循环?
我尝试将时间
设置为不同的值,但无济于事,并且从帮助页面上看不清楚。
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))
最佳答案
我们需要设置interval
选项:
gganimate(p, interval = 0.2)
来自animation package手册,请参阅ani.options
:
interval a positive number to set the time interval of the animation (unit in seconds); default to be 1.
关于r - 使用 rmarkdown 渲染时更改 R ggplot gganimate 的速度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49023515/