Created
September 3, 2015 14:01
-
-
Save bjurban/6fed941516250d947357 to your computer and use it in GitHub Desktop.
plot bivariate kernel density plot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(lattice) | |
library(MASS) | |
splom(iris, upper.panel = function(x, y, subscripts, ...) { | |
if(is.numeric(x) & is.numeric(y)){ | |
# calculate bivariate kernel density | |
v <- current.panel.limits() # allows full bleed by setting limits explicitly | |
f1 <- kde2d(x = x, y = y, n = 50, lims = c(v$xlim, v$ylim)) | |
f <- data.frame(x = f1$x, y = rep(f1$y, each = length(f1$x)), | |
z = as.vector(f1$z)) | |
panel.contourplot(f$x, f$y, f$z, contour = TRUE, | |
subscripts = 1:dim(f)[1], ...) | |
} | |
panel.xyplot(x, y, subscripts = subscripts, ...) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment