r - animate.default() 中的错误 : animation of gg objects not supported

标签 r ggplot2 gganimate

运行以下命令时收到错误消息animate.default() 中的错误:不支持 gg 对象的动画(来自教程 here)

library(ggplot2)
library(gganimate)
library(gapminder)
theme_set(theme_bw())  # pre-set the bw theme.

g <- ggplot(gapminder, aes(gdpPercap, lifeExp, size = pop, frame = year)) +
  geom_point() +
  geom_smooth(aes(group = year), 
              method = "lm", 
              show.legend = FALSE) +
  facet_wrap(~continent, scales = "free") +
  scale_x_log10()  # convert to log scale

animate(g, interval=0.2)

如何渲染动画?

最佳答案

我相信这可能与新版本的 gganimatechange in API 有关。 .

This is the second iteration of the gganimate package. The first, developed by David Robinson had a very different API, and relied on specifying animation frame membership inside aes() blocks in the geom_*() calls. This approach was easy to grasp, but essentially limited in capabilities and has thus been abandoned for a more thorough grammar.

Code written for the old API will not work with this gganimate version and there will not come a future support for it. If you wish to continue using the old API then avoid upgrading gganimate. If you’ve already upgraded and wish to downgrade, the latest version of the old API is available as a GitHub release.

如果您想使用旧 API,可以使用 here 。如果您正在使用或计划使用 >1.0.0 版本,则不会像以前那样在 aes() 中使用 frame。要获得相同的示例功能,请尝试:

ggplot(gapminder, aes(gdpPercap, lifeExp, size = pop)) +
  geom_point() +
  geom_smooth(aes(group = year), 
              method = "lm", 
              show.legend = FALSE) +
  facet_wrap(~continent, scales = "free") +
  scale_x_log10() +
  transition_manual(year)

关于r - animate.default() 中的错误 : animation of gg objects not supported,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58336048/

相关文章:

mysql - 通过 SSH 隧道使用 RMySQL 和 RStudio

r - 如何将上一年和今年的时间序列排列成一个ggplot?

r - 更改gganimate框架标题的标签

r - 使用 gganimate 制作伯努利分布的动画并在 p = 0.5 处获得意外跳跃

r - 如何通过多个变量重新排序条形图

r - 没有填充数字的数据框到矩阵

r - 如何呈现具有多种条件的数据

r - 保持点在gganimate

r - 将文本文件转换为数据框 R

r - 使用 qplot 仅绘制数据的一个子集