0

I did a basic ggplot analysis in R on a dataset of gaze data. The plot shows how the gaze points are distributed in a coordinate system:

current ggplot output

I now want to add a simple slider that lets the points appear or dissappear in time. ifigured out that plotly package should be able to do this. Can you tell me what the code could be that I have to add in order to achieve my goal?

That is my current code:

ggplot(participant_208930511,aes(x = x_mav, y = y_mav, color = cut(time_proxy, breaks = c(1,50,350,405), labels = c("First period","Middle period","Last period")))) + scale_fill_distiller(palette=8, direction=1) + scale_x_continuous(expand = c(0, 0)) + scale_y_continuous(expand = c(0, 0)) + theme(legend.position='n_one') + geom_point(size=1) + guides(color=guide_legend(title="Time category")) + participant_208930511 <- participant_208930511 %>% animation_slider(currentvalue = list(prefix = "time_sec", font = list(color="red")))

And this is what my dataset looks like. Time data is provided under "time_sec" or "time_proxy".

participant question time time_sec time_proxy x x_mav y y_mav <dbl> <dbl> <dbl> <dttm> <dbl> <dbl> <dbl> <dbl> <dbl> 1 208930511 7 1.54e12 2018-12-16 13:18:36 1 0 0 1397 1397 2 208930511 7 1.54e12 2018-12-16 13:18:36 2 234 234 1829 1829 3 208930511 7 1.54e12 2018-12-16 13:18:36 3 344 344 1598 1598 4 208930511 7 1.54e12 2018-12-16 13:18:37 4 -459 -459 1763 1763 5 208930511 7 1.54e12 2018-12-16 13:18:37 5 -629 -629 1560 1560 6 208930511 7 1.54e12 2018-12-16 13:18:37 6 284 284 1061 1061

Thank you in advance!!

  • 1
    Have you seen this? https://plot.ly/r/animations/ The third one from the top may be the one you want to implement? – Majid Apr 24 '19 at 07:47
  • Hey @Majid that's exactly what I want to do yes! But as I am an R newbie,I don' tknow how to implement the slider code into my ggplot code in order to derive the dynamic plot...:) Thanks for helping me out!! – Stefan Christoph Apr 24 '19 at 07:50
  • You need to make your own effort to do this. If you had any problem, sure I will be happy to assist. For the start, your `dataset` is not matching the requirement for animation, unless you are thinking to use `time_proxy` as animation `frame`. – Majid Apr 24 '19 at 10:22
  • Thank you for getting back @Majid Yes exactly, I want to use the "time_proxy" as the animation. What exactly does frame mean? If I understand it correctly I have to create a new frame from the time-proxy in order to refer to this frame when implementing the slider function? – Stefan Christoph Apr 24 '19 at 10:45

0 Answers0