我有一些ggplot对象是通过gganimate动画的,我想改变动画的速度。
这里有一个来自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))发布于 2018-02-28 06:59:48
我们需要设置interval选项:
gganimate(p, interval = 0.2)来自动画软件包手册,请参阅ani.options
interval :设置动画时间间隔(单位为秒)的正数;默认值为1。
https://stackoverflow.com/questions/49023515
复制相似问题