本文介绍了在R gganimate中制作动画时,如何保留先前的数据层?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ggplot和gganimate制作动画。
在以前版本的gganimate中,有一个选项累计,似乎新版本不支持此功能。

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.

以下是代码:

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)


推荐答案

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)

它不会捕获补间,但会在数据

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

这篇关于在R gganimate中制作动画时,如何保留先前的数据层?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 14:34