9

を使用して gif を作成したいのですgganimateが、軸の範囲が 1 つのフレーム内で大きく異なります。これにより、後続のすべてのフレームがスクイーズされます。

のファセットには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)

ここに画像の説明を入力

ここで、データ ポイントの 1 つを極端な値に移動します。これにより、影響を受けない後続のすべてのフレームのポイントが圧迫されます。

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

ここに画像の説明を入力

4

2 に答える 2

9

を試してみることができますview_follow()

1

コード

p <- ggplot(gapminder, aes(gdpPercap, lifeExp, size = pop, color = continent)) +
    geom_point() +
    labs(title = 'Year: {frame_time}', x = 'GDP per capita', y = 'life expectancy') +
    transition_time(year) +
    view_follow()

animate(p)
于 2018-11-24T22:52:51.263 に答える