使用 gganimate 演示实验

Using gganimate to demonstrate an experiment

我正在尝试演示实验的简化版本以供演示。我有一组记录的延迟,带有标记的时间戳,用于在实验期间记录它们。我想使用 geom_point 在 y=0 线上沿 x 轴移动一个点,并在每个记录时间点暂停,向上移动到记录的延迟,然后再向下移动到 y=0 线。

gganimate 是适合这个的包吗,还是我应该考虑在另一个程序中手动设置动画?下面附上我目前拥有的。

require(tidyverse)
require(gganimate)

df <- data.frame(Time = c(0.99,1,1.01,1.99,2,2.01,2.99,3,3.01,3.99,4,4.01,4.99,5,5.01), 
                 Latency = c(0,10,0,0,8,0,0,6,0,0,2,0,0,2,0))

anim <- df %>% ggplot(aes(Time, Latency)) + 
  geom_point(aes(color = Latency))+
  transition_reveal(Time)+
  ease_aes()

anim

我认为您可以使用 gganimate 做到这一点。这是你要找的吗? (只是改变了 gganimate 函数)

library(gganimate)
#> Loading required package: ggplot2

df <- data.frame(Time = c(0.99,1,1.01,1.99,2,2.01,2.99,3,3.01,3.99,4,4.01,4.99,5,5.01), 
                 Latency = c(0,10,0,0,8,0,0,6,0,0,2,0,0,2,0))

ggplot(df, aes(Time, Latency)) + 
  geom_point(aes(color = Latency)) +
  transition_states(Time) 

reprex package (v0.3.0)

于 2020 年 3 月 16 日创建