Adding Histograms and Density plots to a splom
Unfortunately just using panel.histogram
or panel.densityplot does not work. The issue was discussed
on R-help in August/September 2007. In August Deepayan Sarkar offered
this suggestion for adding a density plot:
splom(USArrests, diag.panel = function(x, ...) {
yrng <- current.panel.limits()$ylim
d <- density(x)
d$y <- with(d, yrng[1] + 0.95 * diff(yrng) * y / max(y) )
panel.lines(d)
})
In September Benjamin Barnes suggested this modification to show
histograms:
panel.hist.splom<-function(x, ...) {
yrng <- current.panel.limits()$ylim
h <- hist(x, plot = FALSE)
breaks <- h$breaks
nB <- length(breaks)
y <- h$counts
y <- yrng[1] + 0.95 * diff(yrng) * y / max(y)
panel.rect(breaks[-nB], yrng[1], breaks[-1], y, col="cyan", ...)
}
splom(USArrests, diag.panel = panel.hist.splom)
Luke Tierney 2008-09-18