-1

I have a dataset from Tobii Eyetracker. The dataset looks like this after cetain manipulations

timestamp      xposition      yposition

I used python for collecting the data. The data was recoreded while the participant was looking at the monitor. I want to generate heatmaps for the size of the monitor.

Later I also want to make an image and overlay this heatmap.

I want to use R to generate heatmaps. What is the algorithm to do this or is there is plugin to directly feed my dataset as input?

Experiment Setup:

  1. The time is relative time: 100,100.02,100.04,100.06..and so on incrementing in the order of .02 seconds
  2. The xPosition and yPosition is in Centimeter. From the centre of the monitor.
  3. The background image will be split into 10 row 6 column of square boxes with size 3.4cm each
  4. size of the monitor resolution used is 1920x1080 exact MonitorUsed

The code I ran with error: after exporting using dlmwrite in matlab, i used the GUI in R Studio to load the variables and did the following:

> xPos = myfile[1:278,1]
> yPos = myfile[1:278,2]
> breaks.x <- seq(-23.5, 23.5, length.out = 3.4)
> breaks.y <- seq(-14.1, 14.1, length.out = 3.4)
> int.x <- findInterval(xPos, breaks.x)
> int.y <- findInterval(yPos, breaks.y)
> tb <- table(int.x, int.y)
> image(breaks.x, breaks.y, tb, las=1)
Error in image.default(breaks.x, breaks.y, tb, las = 1) : 
  dimensions of z are not length(x)(-1) times length(y)(-1)

i did it between - to + 23.5 in the x and - to + 14.1 in y so that i matched with the points i generated while do the experiment. The images where plotted only in this region.

Dataset

1
  • Using table() function available both in matlab and r
    – akrv
    Sep 15, 2014 at 8:23

1 Answer 1

2

First of all let's generate some data

# Set RNG seed for reproducibility 
set.seed(12345) 

times <- seq(as.POSIXct("2014-09-08 14:00:00"), 
             as.POSIXct("2014-09-08 16:00:00"), 5)
pos.x <- runif(length(times), 0, 1024)
pos.y <- runif(length(times), 0, 768)

Now we can use findInterval to map each x,y pair to a specific interval, which we define in breaks.x and breaks.y. In this case I used a 20x20 grid, but obviously you can change that at will.
We then use table to generate a contingency table which will be our "position matrix".

breaks.x <- seq(0, 1024, length.out = 20)
breaks.y <- seq(0, 768, length.out = 20)
int.x <- findInterval(pos.x, breaks.x)
int.y <- findInterval(pos.y, breaks.y)

# See below for explanation
int.x <- factor(int.x, levels=1:20)
int.y <- factor(int.y, levels=1:20)

tb <- table(int.x, int.y)

Finally, draw the heatmap

image(breaks.x, breaks.y, tb, las=1)

Note: the two factor calls are necessary because table will otherwise ignore intervals where no data point is present. Converting to a factor effectively forces table to output values even in those slots that have no values in it.

12
  • @arkv: well, since I am not actually using time for the heatmap, I don't see the problem there... Unless you want something else, then please edit your question to be more specific
    – nico
    Sep 8, 2014 at 15:58
  • I see now that time is not used. there are other bits that i have edited in the question
    – akrv
    Sep 8, 2014 at 16:03
  • I want to know if the reading in cm will affect in overlaying backgroud image?
    – akrv
    Sep 8, 2014 at 16:46
  • Units do not really matter, you'll just have to scale everything as needed.
    – nico
    Sep 8, 2014 at 17:14
  • after exporting from matlab using dlmwrite and loading using the GUI in R. I did the following > xPos = myfile[1:278,1] > yPos = myfile[1:278,2] > breaks.x <- seq(-23.5, 23.5, length.out = 3.4) > breaks.y <- seq(-14.1, 14.1, length.out = 3.4) > int.x <- findInterval(xPos, breaks.x) > int.y <- findInterval(yPos, breaks.y) > tb <- table(int.x, int.y) > image(breaks.x, breaks.y, tb, las=1) Error in image.default(breaks.x, breaks.y, tb, las = 1) : dimensions of z are not length(x)(-1) times length(y)(-1)
    – akrv
    Sep 8, 2014 at 17:21

Not the answer you're looking for? Browse other questions tagged or ask your own question.