我正在使用 ggplot 和 gganimate 制作动画。 之前版本的gganimate有一个选项“cumulative”,新版本好像不支持了。
代码如下:
library(ggplot2)
library(gganimate)
x = data.frame(y = c(2000, 2001), x=c(1,2), z=c(3,4))
ggplot(x, aes(x,z))+geom_point() + transition_time(y)
它有效,但我想将第一个数据点保留在散点图中。
我尝试转换数据,但无济于事:
x1 = data.frame(y = c(2000, 2001, 2001), x=c(1,2,1), z=c(3,4,3))
ggplot(x1, aes(x,z))+geom_point() + transition_time(y)
最佳答案
shadow_mark()
是否实现了您想要的行为?
x = data.frame(y = c(2000, 2001, 2002), x=c(1,2,3), z=c(3,4,5))
p <- ggplot(x, aes(x, z)) +
geom_point() +
transition_time(y) +
shadow_mark()
animate(p)
它不会捕获“tween-ing”,但会在 data
中的位置组合处留下一个点。
关于r - 在 R gganimate 中做动画时如何保留以前的数据层?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52242720/