1

I am drawing a heatmap based on some eye-tracking data(X, Y, duration) in R. The function I used to draw the heatmap is MASS::kde2d (learn from internet). Here is my scrip: ######df1 has three colums: Xposition of every fixation, Yposition of every fixation, duration

df2 <- df1[rep(1:nrow(df1),df1$duration),]
n <- 1e3
system.time(
  dens11 <- MASS::kde2d(dfaa$X, dfaa$Y, n=n)
)
image(dens11, col=heat.colors(n, rev=TRUE))t

I tried to add a background image for the heatmap. But it seems that the background image and the heatmap don't use the same coordinate system, which means their (0, 0) and (Xmax, Ymax) are not the same. Here is the scrip used for inport background image:

im <- readPNG("F:/analysisdata/heatmap/original_resize/Nubmer_1.png")
r <- nrow(im)/ncol(im)
plot(c(0,1), c(0, 1), type = "n", xlab = "", ylab = "", asp = 1)
rasterImage(im, 0, 0, 1, 1)
par(new = TRUE)
image(dens11, col=heat.colors(n, rev=TRUE))

Do you know how to make the background image and the heatmap use the same coordinate system? Or any other method to layover the heatmap exactly on the background image?

Kat
  • 15,669
  • 3
  • 18
  • 51
Ziming Jin
  • 11
  • 1

0 Answers0