[R] plotmath: how to create a vector of expressions?

Marius Hofert m_hofert at web.de
Sat Feb 26 00:57:55 CET 2011


Dear expeRts,

I would like to use LaTeX-like symbols in keys via plotmath. Below is a minimal
example. I get:
Error in fun(key = list(x = 0.5, y = 0.8, text = list(list(expression(paste("(",  : 
  first component of text must be vector of labels
What's wrong? How can I create the required vector (of expressions)?

Cheers,

Marius

library(lattice)
val <- matrix(1, nrow = 10, ncol = 3)
nplot <- 10

labs <- sapply(1:3, function(i) substitute(expression(paste("(",i,"), ",l==len,"mm",sep="")), list(len=2*i)))
myplot <- xyplot(0~0,
                 panel=function(...){
                     for(i in 1:3){
                         panel.xyplot(1,val[,i],type="l")
                         panel.text(2,val[nplot,i],label=paste("(",i,")",sep=""))
                     }
                 },
                 key = list(x=0.5,y=0.8,text=list(labs),
                 align=TRUE,transparent=TRUE))
myplot



More information about the R-help mailing list