[R] splom, plotmath: how to add three lines of information with alignment?
baptiste auguie
baptiste.auguie at googlemail.com
Wed Apr 20 01:33:01 CEST 2011
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)
>
>
>
More information about the R-help
mailing list