Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 205372

gganimate with changing scales (axis limits)

$
0
0

I'd like to create a gif using gganimate, but my axis ranges vary wildly in one frame. This is causing all subsequent frames to be squeezed.

In ggplot2's facets, there's an option to have scales="free". Is there a way to have free scales in each frame of gganimate?

Here's an example:

library(gapminder)
library(ggplot2)
library(gganimate)
theme_set(theme_bw())

p <- ggplot(gapminder, aes(gdpPercap, lifeExp, size = pop, color = continent,
                           frame = year)) +
  geom_point() +
  scale_x_log10()

gganimate(p)

enter image description here

Now we move one of the data points to some extreme value. This squeezes the points in all subsequent unaffected frames.

gapminder[1, "lifeExp"] <- 1000
gapminder[1, "gdpPercap"] <- 1e60

p <- ggplot(gapminder, aes(gdpPercap, lifeExp, size = pop, color = continent, 
                           frame = year)) +
  geom_point() +
  scale_x_log10()

gganimate(p)  # smooshed

enter image description here


Viewing all articles
Browse latest Browse all 205372

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>