I have (x,y) data in a text file (data.csv) I would like to make into a heat map.
X Y
-60 -18
60 -62
7 14
-22 -60
59 58
29 22
-58 -18
60 -61
7 14
-
If you are looking at a density plot, where the color represents distribution of the points in the plane, you can use, for example, the kde2d
function from the MASS
library followed by filled.contour
.
A reproducible example:
d <- structure(list(X = c(-60L, 60L, 7L, -22L, 59L, 29L, -58L, 60L,
7L, -21L, 61L, 29L, -57L, -22L, 59L, 29L, -56L, 61L, 8L, -20L,
62L, 30L), Y = c(-18L, -62L, 14L, -60L, 58L, 22L, -18L, -61L,
14L, -59L, 59L, 22L, -18L, -59L, 60L, 24L, -17L, -60L, 16L, -58L,
60L, 23L)), .Names = c("X", "Y"), class = "data.frame", row.names = c(NA,
-22L))
require(MASS)
dens <- kde2d(d$X, d$Y, h=75, n=50) #overrode default bandwidth
filled.contour(dens)
There are lots of other functions that will make you a plot given the density.