My goal is to create a heatmap on top of a human stencil.
The data looks like this:
structure(list(w = c("A", "B", "C", "D", "E"
), f1 = c(129, 111, 128, 129, 126), f2 = c(55, 133, 55, 127,
56)), row.names = c(46L, 111L, 113L, 115L, 118L), class = "data.frame")
I followed these instructions on Stack Overflow and therefore wrote this code:
ggplot(df, aes(f1,f2)) +
annotation_raster(traf, xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf)+
stat_density2d(geom = "polygon", aes(fill=..level..)) +
geom_point(size=0.5)+
scale_fill_gradient(low="green",high="red") +
scale_x_continuous(limits=c(0,dim(traf)[2]),expand=c(0,0))+
scale_y_continuous(limits=c(0,dim(traf)[1]),expand=c(0,0))+
coord_fixed()
Those lines of code produced this image:
Obviously I would need the image to retain its original size so that the points would correspond accordingly to the picture of the human outline. It would be expected that the points would occupy space around the face, neck, and stomach. I am a bit unsure why the offset has occurred because both f1 (x) and f2 (y) were produced on the same picture and no processing or aggregating has been done neither to the data nor the image.
What can I do to a) make the image the original size b) plot the heatmap correctly on top of the human stencil?
The original image is here:
traf <- load.image("50perc.jpg")
plot(traf)