2

I'm trying to demonstrate a shortened version of an experiment for a presentation. I have a set of recorded latencies with a marked timestamp for when they were recorded during the experiment. I want to use geom_point to move a point along the x-axis at the y=0 line and pause at each time point of recording, moving up to the recorded latency before moving back down to the y=0 line.

Is gganimate the right package for this, or should I consider just manually animating this in another program? Attached below is what I currently have.

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
tjebo
  • 21,977
  • 7
  • 58
  • 94

1 Answers1

1

I think you can do that with gganimate. Is this what you were looking for? (just changing the gganimate function)

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) 

Created on 2020-03-16 by the reprex package (v0.3.0)

tjebo
  • 21,977
  • 7
  • 58
  • 94