Skip to content
Prev 257451 / 398506 Next

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

Dear Baptiste,

thank you for your help. I tried to built in your suggestions into the splom. 
Below is the result. I decided to create the plotmath-expressions outside the 
function splom2, this will allow me later to horizontally shift (via phantom,
for example) the table entries so that they will be vertically aligned according 
to the "=" signs. Although an array is allowed to contain expressions, I could 
not manage to create it properly. Do you know a solution?

Cheers,

Marius

library(lattice) 
library(grid)
library(gridExtra)

## splom with customized lower.panel
## x: data
## expr.arr: array of expressions [(i,j,) entry contains expressions which are
##           plotted in a grid table in the lower panel (i,j)]
splom2 <- function(x, expr.arr){
    ## function for creating table 
    table.fun <- function(vec){ # single values for one panel
        grid.table(vec,
                   parse=TRUE, # parse labels as expressions
                   theme=theme.list(
                   gpar.corefill=gpar(fill=NA, col=NA), # make bg transparent
                   core.just="left") # justification of labels
                   ) 
    }
    ## splom
    splom(x, varname.cex=1.4,
          superpanel=function(z, ...){
              panel.pairs(z, upper.panel=panel.splom, lower.panel=function(i,j){
                  table.fun(expr.arr[i,j,])
              }, ...)
          })
}

## create data and array of expressions
d <- 4
x <- matrix(runif(d*1000), ncol=d)
expr.arr <- array(, dim=c(d,d,3), dimnames=c("i","j","val")) # d x d x 3 elements
for(i in 1:d){
    for(j in 1:d){
        # expr.arr[i,j,] <- expression(italic(a)==0, italic(bbb)==0, italic(c)==0) # does no work
	expr.arr[i,j,] <- c(bquote(italic(a)==.(0)), bquote(italic(bbb)==.(0)), bquote(italic(c)==.(0))) # same here
    }
}

## plot
splom2(x, expr.arr)
On 2011-04-20, at 01:33 , baptiste auguie wrote: