From: James Kellner <jkellner_at_plantbio.uga.edu>

Date: Tue, 05 Feb 2008 14:05:04 -0500

R-help_at_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. Received on Tue 05 Feb 2008 - 19:10:24 GMT

Date: Tue, 05 Feb 2008 14:05:04 -0500

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_at_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. Received on Tue 05 Feb 2008 - 19:10:24 GMT

Archive maintained by Robert King, hosted by
the discipline of
statistics at the
University of Newcastle,
Australia.

Archive generated by hypermail 2.2.0, at Tue 05 Feb 2008 - 19:30:14 GMT.

*
Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help.
Please read the posting
guide before posting to the list.
*