相关疑难解决方法(0)

gganimate 改变比例(轴限制)

我想使用 来创建一个 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)

在此处输入图片说明

r axes gganimate

6
推荐指数
1
解决办法
2071
查看次数

标签 统计

axes ×1

gganimate ×1

r ×1