Goal
I would like to zoom in on the GDP of Europe
throughout the years. The phantastic ggforce::facet_zoom
allows this for static plots (i.e., for one specific year) very easily.
Moving scales, however, prove harder than expected. gganimate
seems to take the x-axis limits from the first frame (year == 1952
) and continute until the end of the animation. This related, but code-wise outdated question did not yield an answer, unfortunately. Neither + coord_cartesian(xlim = c(from, to))
, nor facet_zoom(xlim = c(from, to))
seems to be able to influence the facet_zoom
window beyond static limits.
- Is there any way to make
gganimate
'recalculate' thefacet_zoom
scales for every frame?
Ideal result
First frame Last frame Current codelibrary(gapminder)
library(ggplot2)
library(gganimate)
library(ggforce)
p <- ggplot(gapminder, aes(gdpPercap, lifeExp, size = pop, color = continent)) +
geom_point() + scale_x_log10() +
facet_zoom(x = continent == "Europe") +
labs(title = "{frame_time}") +
transition_time(year)
animate(p, nframes = 30)