0

我正在使用 ggplot2 3.0.0 和 gganimate 0.1.1。这是一个MWE:

library(ggplot2)
library(gganimate)

df <- data.frame(year = rep(2000:2010, each = 50),
                 value = rnorm(550))

ggplot(df, aes(x = 0, y = value, frame = factor(year))) +
  geom_violin() -> p
gganimate(p)

这将创建一个动画,其中每一帧看起来都像这样

电流输出

而我希望每一帧都像这样占据整个情节

期望的输出

我怎么能去调整我的代码来得到这个结果?

编辑

就是我想制作的,这次使用的是实际数据。我通过手动将动画的每一帧拼接在一起来做到这一点,但这种方式对于更复杂的情节是不可持续的,所以我希望使用 gganimate 来代替。

4

1 回答 1

1

1

只需使用transition_states()or transition_time()

代码

ggplot(df, aes(x = 0, y = value)) +
    geom_violin() +
    transition_states(year, transition_length = 3, state_length = 1) +
    labs(title = "{closest_state}")

数据

set.seed(1701)
df <- data.frame(year = c(rep(2000:2010, each = 50)),
                 value = rnorm(550))
于 2018-10-16T10:36:55.360 回答