使用眼动仪数据创建带有R的热图

时间:2013-04-20 09:07:04

标签: r csv ggplot2 heatmap

我有一个由以下数据组成的表

frame,X,Y

这是来自多个眼动追踪分析的结果数据。 现在我想用R创建一个Heatmap,如下所示 enter image description here

我尝试了几个在线发现的脚本,但没有一个给我这个结果。

我该怎么办?


这里有一些示例数据 忽略前两列

task,visualization,frame,X,Y
1,b,1,383,221
1,b,1,632,356
1,b,1,947,663
1,b,1,546,206
1,b,1,488,272    
1,b,1,578,752
1,b,1,415,261
1,b,1,693,158
1,b,1,684,528
1,b,1,592,67
1,b,1,393,180
1,b,1,1033,709
1,b,1,1080,739
1,b,1,711,523
1,b,1,1246,49
1,b,1,742,69
1,b,1,601,370
1,b,10,902,684
1,b,10,517,241
1,b,10,583,86
1,b,10,582,754
1,b,10,426,257
1,b,10,575,229
1,b,10,697,150
1,b,10,379,520
1,b,10,390,286
1,b,10,618,396
1,b,10,710,143
1,b,10,383,188
1,b,10,1026,713
1,b,10,1078,625
1,b,10,713,521

1 个答案:

答案 0 :(得分:7)

您可以使用stat_bin2d中的ggplot2轻松获得此类情节:

library(ggplot2)
ggplot(dat, aes(x = X, y = Y)) + stat_bin2d(bins = 10)

enter image description here

这可以进行简单的分级,因为@RomanLustrik建议您也可以执行某种内核平滑。这也可以使用ggplot2

完成
ggplot(dat, aes(x = X, y = Y)) + 
 stat_density2d(geom = "tile", aes(fill = ..density..), contour = FALSE) + 
 geom_point()

enter image description here 请注意,dat是您提供的示例数据,将您的数据设为data.frame

dat = read.table(textConnection("task,visualization,frame,X,Y
    1,b,1,383,221
    1,b,1,632,356
    1,b,1,947,663
    1,b,1,546,206
    1,b,1,488,272    
    1,b,1,578,752
    1,b,1,415,261
    1,b,1,693,158
    1,b,1,684,528
    1,b,1,592,67
    1,b,1,393,180
    1,b,1,1033,709
    1,b,1,1080,739
    1,b,1,711,523
    1,b,1,1246,49
    1,b,1,742,69
    1,b,1,601,370
    1,b,10,902,684
    1,b,10,517,241
    1,b,10,583,86
    1,b,10,582,754
    1,b,10,426,257
    1,b,10,575,229
    1,b,10,697,150
    1,b,10,379,520
    1,b,10,390,286
    1,b,10,618,396
    1,b,10,710,143
    1,b,10,383,188
    1,b,10,1026,713
    1,b,10,1078,625
    1,b,10,713,521"), header = TRUE, sep = ",")