[R] How to put given values in lower triangle of splom-plot?

Deepayan Sarkar deepayan.sarkar at gmail.com
Wed Sep 24 00:56:28 CEST 2008


On Sun, Sep 21, 2008 at 2:11 AM, Hofert Marius <m_hofert at web.de> wrote:
> Dear R-experts,
>
> I have found a splom-modification online which is given below. This works
> perfectly, but I would like to have a matrix of given correlation values to
> be used in the lower triangular part (lower.panel) of the splom-plot instead
> of calculated correlation values. Here is the matrix I would like to use (it
> can be any other convenient data structure):
>
> mymat=matrix(0,nrow=3,ncol=3)
> mymat[1,2]=0.2
> mymat[1,3]=0.2
> mymat[2,3]=0.5
>
> If one can determine inside the lower.panel-function which columns of "data"
> are used for the current pairwise scatter plot, it should be easy to get the
> correct entries of "mymat", but how is this achieved? It would then be also
> possible to build a data structure of locations so that one can place the
> entries wherever convenient inside the gray rectangles.

You do not have access to the row and column numbers inside the panel
function. The intention is to have the `panel' function handle pairs
of variables, and the `superpanel' function to handle the global data
frame; so one approach could be to replace the default superpanel
function:


mymat <- mymat + t(mymat) # to fill in lower diagonal

splom(~data[,1:3],
      superpanel = function(z, ...) {
          mymat.df <-
              data.frame(vals = as.vector(mymat),
                         row = as.vector(row(mymat)),
                         col = as.vector(col(mymat)))
          mymat.df <- subset(mymat.df, col < row)
          with(mymat.df,
           {
               panel.rect(x = row, y = col, width = 1, height = 1,
                          col = gray(500:1000/1000)[round(501 - 500 * vals)])
               panel.text(x = row, y = col, labels = round(vals, 2))
           })
          panel.pairs(z, upper.panel = panel.splom,
                      lower.panel = function(...) {},
                      ...)
      },
      cex=0.2,
      aspect=1,
      pscales=0,
      varnames=c("Component 1","Component 2","Component 3"),
      xlab="",ylab="")


This uses one undocumented fact (which I will shortly document),
namely, that the coordinate system set up before 'superpanel' is
called has both x- and y-limits set to c(0.5, ncol(z)+0.5).

-Deepayan



More information about the R-help mailing list