plotting and coloring data on irregular grid
I have data in the form (x, y, z) where x and y are not on a regular grid. I wish to display a 2D colormap of these data, with intensity (say, grey scale) mapped to the z variable. An obvious solution is to interpolate (see below) on a regular grid, d <- data.frame(x=runif(1e3, 0, 30), y=runif(1e3, 0, 30)) d$z = (d$x - 15)^2 + (d$y - 15)^2 library(akima) d2 <- with(d, interp(x, y, z, xo=seq(0, 30, length = 30), yo=seq(0, 30, length = 50), duplicate="mean")) pal1 <- grey(seq(0,1,leng=500)) with(d2, image(sort(x), sort(y), z, useRaster=TRUE, col = pal1)) points(d$x, d$y, col="white", bg=grey(d$z