Skip to content

Instantly share code, notes, and snippets.

@davebraze
Created March 6, 2021 19:33
Show Gist options
  • Save davebraze/497f610aef17b4fd04962a7a61ce667d to your computer and use it in GitHub Desktop.
Save davebraze/497f610aef17b4fd04962a7a61ce667d to your computer and use it in GitHub Desktop.
Plot Fixations (gaze data), as for pre-analytic screening
library(tidyverse)
library(ggplot2)
library(cowplot)
## make some data. Assume display screen stimulus display of 1024x768
n <- 2000 # n fixations
lx <- 512-200
rx <- 512+200
cx <- 512
sdx <- 100
my <- 768/2
sdy <- 150
set.seed(1234)
L <- tibble(x=rnorm(n=n, m=lx, sd=sdx),
y=rnorm(n=n, m=my, sd=sdy))
R <- tibble(x=rnorm(n=n, m=rx, sd=sdy))
C <- tibble(x=rnorm(n=n*.3, m=cx, sd=sdx*.33),
y=rnorm(n=n*.3, m=my, sd=sdy*.33))
df <- bind_rows(R, L, C)
df %>%
ggplot(aes(x=x, y=y)) +
geom_point(size=2, alpha=.1, fill=NA) + # low values of size and alpha help see through overplotting
annotate(geom="rect", xmin=0, xmax=1024, ymin=0, ymax=768, fill=NA, color="black") + ## display screen rect
geom_hline(aes(yintercept=768/2), color="grey70", size=1) +
geom_vline(aes(xintercept=1024/2), color="grey70", size=1) +
scale_x_continuous(limits=c(0,1024), oob=scales::squish) + ## squish forces offscreen fixations to be included in plot
scale_y_continuous(limits=c(768,0), oob=scales::squish, trans="reverse") + ## origin for most eye-trackers is UL corner
# theme_nothing() +
theme_cowplot()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment