Plotting

The package provides basic plotting functionality via function that uses ggplot2 as a back end. This means that you can extend the plot by adding further layers and geoms. Below is the basic code that shows how to use ggplot2 to generate a custom plot replicating the .

library(eyelinkReader)
#> Loading required package: RcppProgress
#> Loading required package: rlang
library(ggplot2)

data(gaze)

# extracting fixations and saccades for the first trial
fixations <- gaze$fixations[gaze$fixations$trial == 1, ]
saccades <- gaze$saccades[gaze$saccades$trial == 1, ]

 ggplot() +
  
  # enforce same scaling, as on the screen
  coord_equal(expand=FALSE) +
   
  # define screen limits and INVERSE y-axis to match Eyelink
  scale_x_continuous(name = "x", limits = gaze$display_coords[c(1, 3)]) +
  scale_y_reverse(name = "y", limits = gaze$display_coords[c(4, 2)]) +
   
  # draw fixations as circles
  geom_point(data = fixations, aes_string(x = "gavx", y = "gavy", size = "duration"), alpha=0.3) +
   
  # draw saccades as line segments
  geom_segment(data = saccades, aes_string(x = "gstx", y = "gsty", xend = "genx", yend = "geny", color = "sttime_rel")) +
   
  # better legend titles
  labs(size = "Fixation duration [ms]",
       color = "Saccade onset [ms]")
#> Warning: `aes_string()` was deprecated in ggplot2 3.0.0.
#> i Please use tidy evaluation idioms with `aes()`.
#> i See also `vignette("ggplot2-in-packages")` for more information.
#> This warning is displayed once every 8 hours.
#> Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
#> generated.