I would like to combine multiple plots (one of which is a pairs plot) in one output display: While this works well: layout(matrix(c(1,2,3,3,3,3), ncol=2, byrow=T)) data <- matrix(rnorm(1000), ncol=10) boxplot(data) hist(data) plot(data) This doesn't: (because the pairs function seems to override the layout parameters?) layout(matrix(c(1,2,3,3,3,3), ncol=2, byrow=T)) data <- matrix(rnorm(1000), ncol=10) boxplot(data) hist(data) pairs(data) Thanks for your help, Uli --- Ulrich Schlecht, PhD 855 South California Avenue Palo Alto, CA-94304, USA [[alternative HTML version deleted]]
David Winsemius
2011-Oct-28 01:24 UTC
[R] combining pairs plot with other plots in one output
On Oct 27, 2011, at 6:27 PM, Ulrich wrote:> I would like to combine multiple plots (one of which is a pairs plot) > in one output display: > > > While this works well: > > layout(matrix(c(1,2,3,3,3,3), ncol=2, byrow=T)) > data <- matrix(rnorm(1000), ncol=10) > boxplot(data) > hist(data) > plot(data) > > > > This doesn't: > (because the pairs function seems to override the layout parameters?)Right. But you have not specified what should go in what location.> > layout(matrix(c(1,2,3,3,3,3), ncol=2, byrow=T)) > data <- matrix(rnorm(1000), ncol=10) > boxplot(data) > hist(data) > pairs(data)You should look at the ?pairs page. It implements a panel.hist function that can be offered to diag.panel: panel.hist <- function(x, ...) { usr <- par("usr"); on.exit(par(usr)) par(usr = c(usr[1:2], 0, 1.5) ) h <- hist(x, plot = FALSE) breaks <- h$breaks; nB <- length(breaks) y <- h$counts; y <- y/max(y) rect(breaks[-nB], 0, breaks[-1], y, col="cyan", ...) } pairs(data, diag.panel=panel.hist, upper.panel=panel.smooth) There is also a panel.pairs function in package lattice, but you would need to create your page layout with grid calls rather than base graphics. -- David Winsemius, MD West Hartford, CT