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

baptiste auguie baptiste.auguie at googlemail.com
Tue Apr 19 07:19:09 CEST 2011


On 19 April 2011 17:06, Marius Hofert <m_hofert at web.de> wrote:
> Dear Baptiste,
>
> thanks for your answer.
> Unfortunately, I get the error "Error using packet 1 invalid 'times' argument" when executing your code. Hmm... not sure where the problem is.
>

Oops, – sorry, my mistake. For this code to work you'll need a more
recent version of gridExtra than the one on CRAN. You can get it here:
http://code.google.com/p/gridextra/

baptiste

> Cheers,
>
> Marius
>
> On 2011-04-19, at 24:03 , baptiste auguie wrote:
>
>> Hi,
>>
>> Does this help?
>>
>> library(gridExtra)
>>
>> my.title = function(expressions) {
>>  grid.table(expressions, parse=TRUE,
>>             theme=theme.list(gpar.corefill = gpar(fill = NA, col = NA),
>>               core.just = "left"))
>> }
>>
>> e = expression(alpha,"text", italic(italic),
>>    hat(beta), integral(f(x)*dx, a, b))
>>
>> library(lattice)
>>
>> xyplot(1~1, panel=function(...) my.title(e) )
>>
>> HTH,
>>
>> baptiste
>>
>>
>>
>> On 19 April 2011 08:43, Marius Hofert <m_hofert at web.de> wrote:
>>> Dear expeRts,
>>>
>>> I would like to create a scatter plot matrix with splom(). The lower panel should
>>> contain some additional information about the samples shown in the upper panel
>>> plot, see the splom() call below. Now two questions came up:
>>> (1) The lower panels show "tau" and "alpha" on top of each other. How can I plot
>>> *three* expressions on top of each other? I tried several approaches (see the trials below),
>>> but couldn't manage to get this to work properly.
>>> (2) Is there the possibility to plot the two/three lines (containing "tau = ..", "alpha = ..")
>>> aligend according to the equality sign?
>>>
>>> Cheers,
>>>
>>> Marius
>>>
>>>
>>> library(lattice)
>>>
>>> f <- function(i,j) i+j
>>>
>>> U <- matrix(runif(3000), ncol=3)
>>>
>>> splom(U,
>>>      superpanel=function(z, ...){
>>>          tau <- cor(U, method="kendall")
>>>          df=data.frame(rows=as.vector(row(tau)), columns=as.vector(col(tau)),
>>>          vals=as.vector(tau)) # data frame of row indices, column indices, and tau values
>>>          df=subset(df,columns<rows) # subset for lower left triangle
>>>          with(df,{
>>>              panel.text(x=rows, y=columns,
>>>                         labels=as.expression(unlist(lapply(1:length(vals),
>>>                             function(i) substitute(atop(tau==tau.,alpha==alpha.),
>>>                                                    list(tau.=vals[i], alpha.=round(vals[i],3)) ) ))) )
>>>          })
>>>          panel.pairs(z, upper.panel=panel.splom, lower.panel=function(...){}, ...)
>>>      })
>>>
>>> ## some minimal "trial" examples:
>>> plot(0,0,main=paste("alpha=1","\n","beta=2","\n","gamma=3",sep=""))
>>> plot(0,0,main=expression(atop(atop(alpha==1, beta==2), gamma==3)))
>>> plot(0,0,main=paste(expression(alpha==1),"\n",expression(beta==2),"\n",
>>>         expression(gamma==3), sep=""))
>>> plot(0,0,main=substitute(paste(alpha==1,x,beta==2,x,
>>>         gamma==3, sep=""), list(x="\n")))
>>> plot(0,0,main=expression(cat(alpha==1, "\n", beta==2, "\n", gamma==3, sep="")))
>>> plot(0,0,main=cat(expression(alpha==1), "\n", expression(beta==2), "\n",
>>>         expression(gamma==3), sep=""))
>>>
>>> ______________________________________________
>>> 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.
>>>
>
>



More information about the R-help mailing list