1

I have logs of mouse movement that is coordinates and timestamp .I want to plot the mouse movement using this log how can I do this I have no idea what API or what can be used to do the same.I want to know how start with if there is some way which exist.

I have found this website I want do something similar with my log file.

My log is as follows

 Date     hr:min:sec ms     x      y
    13/6/2020  13:13:33 521    291    283
    13/6/2020  13:13:33 638    273    234
    13/6/2020  13:13:33 647    272    233
    13/6/2020  13:13:33 657    271    231
    13/6/2020  13:13:33 667    269    230
    13/6/2020  13:13:33 677    268    229
    13/6/2020  13:13:33 687    267    228
    13/6/2020  13:13:33 697    264    226
Nurav
  • 167
  • 1
  • 3
  • 15

1 Answers1

1

You're looking for geom_path() from ggplot2. The geom will connect a line between all your observations based on the order they appear in the dataframe. So, here's some x,y data that's expanded a bit:

df <- data.frame(
  x=c(291,273,272,271,269,268,267,264,262,261,261,265,268,280,290),
  y=c(283,234,233,231,230,229,228,226,230,235,237,248,252,246,235)
)

And some code to make a simple plot using geom_path():

p <- ggplot(df, aes(x=x,y=y)) + theme_classic() +
    geom_path(color='blue') + geom_point()
p

enter image description here

If you want, you can even save that as an animation based on your time points. See the code below using the gganimate package:

library(gganimate)
df$time <- 1:15
a <- p + transition_reveal(time)
animate(a, fps=20)

enter image description here

chemdork123
  • 12,369
  • 2
  • 16
  • 32
  • `df <- data.frame( x=c(291,273,272,271,269,268,267,264,262,261,261,265,268,280,290), y=c(283,234,233,231,230,229,228,226,230,235,237,248,252,246,235) )` How you are inserting it from data object ,which has x and y coordinates ? – Nurav Jun 16 '20 at 12:12
  • How to fetch directly from data object which is created by using `mydata<-read.csv()` and has x and y as coloumns – Nurav Jun 16 '20 at 12:19
  • Well, based on your question your dataset has columns named "x" and "y". You would be able to create those plots using the code above (but use `mydata` instead of `df`). I also am assuming that the dataset you have is arranged/ordered by time. That's important if you're drawing a path based on the time, since `geom_path()` just takes the order the observations appear in your dataframe. Is that answering your question? – chemdork123 Jun 16 '20 at 13:02
  • how can we fetch that from data set you wrote it manually? – Nurav Jun 16 '20 at 13:52
  • How to create animation like it is creating frames 100 frames how to animate that? – Nurav Jun 16 '20 at 14:28
  • The animation is from the `gganimate` package. Some information to get you started [can be found on their site](https://gganimate.com). You [could also check this article with some examples of animation](https://www.datanovia.com/en/blog/gganimate-how-to-create-plots-with-beautiful-animation-in-r/). – chemdork123 Jun 16 '20 at 14:35