我开始熟悉gganimate
了,但我想进一步扩展我的gif。
例如,我可以在gganimate
中对一个变量添加frame
,但是如果我想动画显示添加完全新的图层/几何对象/变量的过程呢?
这是一个标准的gganimate
示例:
library(tidyverse)
library(gganimate)
p <- ggplot(mtcars, aes(x = hp, y = mpg, frame = cyl)) +
geom_point()
gg_animate(p)
但如果我想让gif动起来怎么办:
# frame 1
ggplot(mtcars, aes(x = hp, y = mpg)) +
geom_point()
# frame 2
ggplot(mtcars, aes(x = hp, y = mpg)) +
geom_point(aes(color = factor(cyl)))
# frame 3
ggplot(mtcars, aes(x = hp, y = mpg)) +
geom_point(aes(color = factor(cyl), size = wt))
# frame 4
ggplot(mtcars, aes(x = hp, y = mpg)) +
geom_point(aes(color = factor(cyl), size = wt)) +
labs(title = "MTCARS")
这该如何实现呢?
saveGIF
的帮助指向ani.options
,其中包括interval
,它设置每个帧停留的时间(以秒为单位)。因此,只需添加interval = 3
就可以让每个帧持续 3 秒。 - Mark Peterson