I am using R 2.6.1 on a 64 bit PC running Windows XP Pro. My main problem is that I want to produce a scatter plot with density estimation, where the colors of points correspond to a kernel density estimate at the location of the points. I have not found a package that will do this.
If there is no package, one option would to estimate the bivariate density first, and then use it to define a color table for the points. If I obtain a bivariate kernel density for X and Y coordinates as follows: require(MASS) x.coord <- rnorm(1000) y.coord <- rnorm(1000) kernel <- kde2d(x.coord, y.coord, n = 100) par(mfrow=c(2, 1)) image(kernel) points(x.coord, y.coord) plot(x.coord, y.coord, main="I want to color these points using the kernel density") how can I extract the kernel density estimates at the x.coord and y.coord locations for each point? What I would like is a matrix with three columns for "X", "Y" and "DENSITY", like this: > matrix X Y DENSITY 1 1.56 -0.03 0.05 ... Is there an easier way to do this? Thanks in advance, Jim [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.