Skip to content
Prev 257431 / 398506 Next

splom, plotmath: how to add three lines of information with alignment?

Dear Baptiste,

there is one tricky part left: how can I create a matrix with the grid.table() 
objects as output? Is this possible? If not, maybe one can try to work with
panel.splom (which can address single panels and thus call info() for each
row-column index pair (i,j)), but I'm not sure if this will work.

Cheers,

Marius

library(lattice)
library(gridExtra)

splom2 <- function(x, a, b, c){
    ## function for the additional information
    info <- function(a., b., c.){ # single values for one panel
        grid.table(c(bquote(italic(a)==.(a.)), 
                     bquote(italic(b)==.(b.)), 
                     bquote(italic(c)==.(c.))
                     ),
                   parse=TRUE, # parse labels as expressions
                   theme=theme.list(
                   gpar.corefill=gpar(fill=NA, col=NA), # make bg transparent
                   core.just="right") # justification of labels
                   ) 
    }
    labs <- matrix(, nrow=ncol(x), ncol=ncol(x)) # should be a matrix of grid.table() objects
    for(i in 1:ncol(x)) for(j in 1:ncol(x)) labs[i,j] <- info(a.=a[i,j], b.=b[i,j], c.=c[i,j])
    ## splom
    splom(x, superpanel=function(z,...){
              df=data.frame(rows=as.vector(row(a)), 
              columns=as.vector(col(a)), labs=as.vector(labs))
              df=subset(df,columns<rows) # subset for lower left triangle
              with(df,{
                  panel.text(x=rows, y=columns, labels=labs)
              })
              panel.pairs(z, upper.panel=panel.splom, lower.panel=function(...){}, ...)
          })
}

## generate data
U <- matrix(runif(3000), ncol=3)

## build information
a <- cor(U, method="kendall")
b <- diag(ncol=3, nrow=3)
c <- diag(ncol=3, nrow=3)

## plot with information
splom2(U, a, b, c)
On 2011-04-19, at 23:04 , baptiste auguie wrote: