5

I am working in a heat map for some eye tracking data. I figured out how to do the heat map and it is very compelling. This is the code:

ggplot(eyematrixCorrectMatchControl, aes(x = CURRENT_FIX_X, y =CURRENT_FIX_Y)) +
annotation_raster(image, -Inf, Inf, -Inf, Inf, interpolate = TRUE) +
stat_density2d(data= eyematrixCorrectMatchControl, aes(x = CURRENT_FIX_X, y =CURRENT_FIX_Y, fill = ..level.., alpha = ..level..), size= 10, bins= 50, geom='polygon') + 
theme_bw() +scale_fill_gradient(low = "blue", high = "red") +
scale_alpha_continuous(range=c(0.01,0.25) , guide = FALSE) +
coord_cartesian(xlim= c(0,1024), ylim= c(0,768))+
scale_y_reverse() + 
theme(axis.line=element_blank(),
      axis.text.x=element_blank(),
      axis.text.y=element_blank(),
      axis.ticks=element_blank(),
      axis.title.x=element_blank(),
      axis.title.y=element_blank())

With this code, I obtain this image: enter image description here

However, I don't understand some things. I thought that this code would give me a graph the number of fixations in a specific area (the more fixation the redder the area is). However, looking at the legend I am not sure what this graph shows. How can I obtain a graph showing the number of fixations? I would also like that the legend reflects the number of fixations, so the redder the more fixations. Any idea??

I edit to add some extra information that might be useful. In my original dataframe I also have a variable called fixation_index. I think that I have to include this variable somewhere, but not really sure.

Thanks!

unomas83
  • 151
  • 1
  • 9
  • 1
    The density sums to one, i.e. the legend refers to the fraction of fixations instead of the number. – Axeman Oct 12 '15 at 09:46
  • Thanks for your comment. Any idea about how to change that? – unomas83 Oct 12 '15 at 09:50
  • Perhaps you instead `fill = ..level..` you can use `fill = ..level.. * [total number of fixations]` – Axeman Oct 12 '15 at 09:56
  • I answered a similar question in GIS contexts the other day. I wonder if [this](http://stackoverflow.com/questions/32522378/density-count-in-heatmaps/32528744#32528744) will help you – jazzurro Oct 12 '15 at 10:05
  • 1
    you could also try `stat_binhex` / `geom_hex` to see if that provides enough granularity. – hrbrmstr Oct 12 '15 at 10:50

1 Answers1

0

Heatmap.2 offers a histogram option that correlates color with the density count. It looks like this.

datadan
  • 55
  • 1
  • 8
  • thanks for your reply! Could you provide an example of code? – unomas83 Oct 12 '15 at 13:18
  • @unomas83:
    heatmap.2(yourmatrixhere, xlab="choose your label at bottom here", col=brewer.pal(9,"Oranges"),trace="none", margins = c(4, 10), main = "Title at top here", key=TRUE)
    – datadan Oct 12 '15 at 22:15