我想使用 来创建一个 gif gganimate,但我的轴范围在一帧中变化很大。这导致所有后续帧都被压缩。
在ggplot2某些方面,有一个选项可以让scales="free". 有没有办法在 的每一帧中都有自由比例gganimate?
下面是一个例子:
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)
Run Code Online (Sandbox Code Playgroud)
现在我们将其中一个数据点移动到某个极值。这会挤压所有后续未受影响帧中的点。
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
Run Code Online (Sandbox Code Playgroud)