Skip to content
Back to formatted view

Raw Message

Message-ID: <07AA0756-76E6-4C8C-82CA-6F30D68258FA@comcast.net>
Date: 2011-10-28T01:24:09Z
From: David Winsemius
Subject: combining pairs plot with other plots in one output
In-Reply-To: <4473466F-D625-44DA-9D9F-1E490DF727B2@stanford.edu>

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