0
votes

I have the coordinated (x,y) extracted from a video of a moving object per each frame. The data frame look like that:

data_coord

          x   y frame
    1   383 222     1
    2   378 224     2
    3   378 224     3
    4   378 224     4
    5   378 224     5
    6   378 224     6
    7   378 224     7
    8   378 224     8
    9   378 224     9
    10  378 224    10
    11  378 224    11
    12  378 224    12
    13  378 224    13
    14  378 224    14
    15  378 224    15
    

Ideally, I am looking for a way to plot the (x,y) positions over time (frames), so that the dyads (x,y) follow the frame order. I would like to have the trajectory (given by the x,y coordinates) of the moving object over time. I thought about a 3D graph with the z axis representing the frame but I do not do how to make it.

1
Hello! It's going to be easier if you give us representative data, possibly by pasting the output of calling dput(data_coord). Also, it would be good to show the code you already have/are working on.sjp

1 Answers

0
votes

You can use the gganimate package to do so.

Calling df the data you provided, you can do:

library(ggplot2)
ggplot(df) +
  geom_point(aes(x = x, y = y)) +
  gganimate::transition_time(frame)

enter image description here

gganimate offers a lot of other function to represent data over time, such as transition_states or transition_reveal, depending on what you want to do.

You can then export the animation with anim_save() function.

Edit: Plus, you can trace the trajectory over time using shadow_wake() function, which can trace the object movements.