[R] Polygon issue in lattice & Bivariate density estimation

Andrewjohnclose a.j.close at ncl.ac.uk
Fri Aug 8 16:40:52 CEST 2008


Dear all,

I am trying to set a specific bandwidth for a bivariate kernel density
estimation and then plot it in lattice: managed all that except that the
plot appears to have an issue regards the setting of the polygon and as a
result I end up with horizontal lines disecting my plotting region. If I
lower the bandwidth excessively then the issue resolves itself, but this
defeats the object as I wish and need h=0.8481.

Any suggestions would be much appreciated. Thank you

Here is the code I have used:
library(lattice)
library(KernSmooth)
#####
CAPEL2=read.csv("CAPEL2.csv",header=T,row.names=1)
#####
panel.density2d <-
    function(x, y, nlevels = 10, bandwidth, ...)
{
    k2d <- bkde2D(na.omit(cbind(x, y)), bandwidth = bandwidth)
    cl <-
        contourLines(x = k2d$x1, y = k2d$x2, z = k2d$fhat,
                     nlevels = nlevels)
    lapply(cl, panel.polygon, ...)
}
#####
xyplot(PCO2~PCO1,data=CAPEL2,panel = panel.density2d,bandwidth=0.8481)
http://www.nabble.com/file/p18893107/CAPEL2.csv CAPEL2.csv 
-- 
View this message in context: http://www.nabble.com/Polygon-issue-in-lattice---Bivariate-density-estimation-tp18893107p18893107.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list