r - 在 R gganimate 中做动画时如何保留以前的数据层?

标签 r animation ggplot2 gif gganimate

我正在使用 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)

enter image description here

它不会捕获“tween-ing”,但会在 data 中的位置组合处留下一个点。

关于r - 在 R gganimate 中做动画时如何保留以前的数据层?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52242720/

相关文章:

r - 使用打开的 mapquestapi 在 R 中对批处理地址进行地理编码

r - 取消嵌套或取消切割包含不同长度列表的数据帧

r - 在 R 中创建带有自定义标签的传单 map

r - ggplot 的注释中的文本格式

r - 绘制网格的 3D 地形图

r - ggplot2:热图中的平均行

xml - 将数据从 XML 文件导入 R

java - 等待框架创建

animation - 使用带有两个嵌套循环的 LaTeX animate 和 Tikz

firefox - 面具在 Gecko 中不起作用