【问题标题】:Change speed of R ggplot gganimate when using rmarkdown render使用 rmarkdown 渲染时更改 R ggplot gganimate 的速度
【发布时间】: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


【解决方案1】:

我们需要设置interval选项:

gganimate(p, interval = 0.2)

来自animation package手册,见ani.options

interval 正数,设置动画的时间间隔(单位为秒);默认为 1。

【讨论】:

  • 谢谢,知道使用rmarkdown::render 时这是如何工作的吗?详情请查看更新后的问题,谢谢!
  • @jmuhlenkamp 我建议将此作为一个新问题提出。
猜你喜欢
  • 2020-11-12
  • 2019-12-16
  • 1970-01-01
  • 1970-01-01
  • 2012-08-07
  • 1970-01-01
  • 2015-09-27
  • 2015-05-18
  • 1970-01-01
相关资源
最近更新 更多