Re: [R] splom, plotmath: how to add three lines of information with alignment?

From: baptiste auguie <baptiste.auguie_at_googlemail.com>
Date: Wed, 20 Apr 2011 11:33:01 +1200

Hi,

You may want to wait advice from someone who actually understands (the labyrinth that is) lattice's help for splom, but the following might be a start. I didn't understand what values you actually wanted displayed in the lower triangle panels, so I made up some random ones in a 3x3 matrix of 3-vectors.

library(lattice)
library(gridExtra)

info <- function(x){

  grid.table(c(bquote(italic(a)==.(x[1])),
               bquote(italic(b)==.(x[2])),
               bquote(italic(c)==.(x[3]))),
             core.just="left",
             parse=TRUE)

}

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

splom(U,

     superpanel=function(z, ...){
       ## dummy 3x3 matrix of 3 values to diplay
       values <- replicate(9, round(rnorm(3), 3), simplify=FALSE)
       dummy <- matrix(values, ncol=3, byrow=F)
       panel.pairs(z, upper.panel=panel.splom,
                   lower.panel=function(i, j, ...){
                     print(paste(i,j)) # current panel indices
                     info(dummy[i,j] [[1]]) # access the list elements
                   }, ...)
       })

HTH, baptiste

On 20 April 2011 10:17, Marius Hofert <m_hofert_at_web.de> wrote:
> 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)
>
>
>



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Tue 19 Apr 2011 - 23:36:51 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 20 Apr 2011 - 07:40:32 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive