运行以下命令时收到错误消息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)
如何渲染动画?
最佳答案
我相信这可能与新版本的 gganimate
和 change 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/