animate.default() 中的错误:不支持 gg 对象的动画

Error in animate.default() : animation of gg objects not supported

在 运行 以下内容(来自教程 here)时收到错误消息 Error in animate.default() : animation of gg objects not supported

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)