问题
Getting error message Error in animate.default() : animation of gg objects not supported
when running the following (from tutorial 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)
How can the animation be rendered?
回答1:
I believe this may have to do with the newer version of gganimate
and 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.
If you wish to use the old API it is available here. If you are using or plan to use version >1.0.0, then would not use frame
in aes()
as previously done. To get the same example functional try:
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)
来源:https://stackoverflow.com/questions/58336048/error-in-animate-default-animation-of-gg-objects-not-supported