Sorry, that should have been df <- data.frame(x=as.vector(rasterx.im(Z)), y=as.vector(rastery.im(Z)), count=as.vector(as.matrix(Z))) Adrian