How to keep previous layers of data while doing animation in R gganimate?

浪子不回头ぞ 提交于 2019-12-24 08:43:22

问题


I'm doing animation using ggplot and gganimate. In the previous version of gganimate there was an option "cumulative", seem that new version does not support this.

Here's the code:

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)

It works, but I want to keep the first data point at the scatterplot.

I tried to trasform the data, but it doesn't help:

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)

回答1:


Does shadow_mark() achieve your desired behavior?

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)

It doesn't capture the "tween-ing" but it does leave a point at location combinations in data.



来源:https://stackoverflow.com/questions/52242720/how-to-keep-previous-layers-of-data-while-doing-animation-in-r-gganimate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!