[R] How to use expression in label with xYplot

PANTERA Laurent laurent.pantera at irsn.fr
Wed Jun 22 09:14:03 CEST 2005


Dear R-List,

 I want to use the label function (from Hmisc library) to allow for the
names of my isotopes.

library(Hmisc)
library(lattice)
library(grid)
num <- c("78","137","129m")
nom <- c("Ge","Cs","Te")
df <- data.frame(GE78=seq(nom),CS137=seq(nom),TE129m=seq(nom))

if I use this function to create the labels :

lab <- function(i)
  as.expression(bquote(italic(phantom(0)^{.(num[i])}*.(nom[i]))))

label(df$GE78) <-  lab(1)
label(df$CS137) <-  lab(2)
label(df$TE129m) <-  lab(3)

all works fine when I use text and xyplot :

plot(1:10)
text(6,6,labels=label(df$CS137))
xyplot(CS137~TE129m,data=df,xlab=label(df$CS137),ylab=label(df$TE129m))

but xYplot doesn't work fine

xYplot(CS137~TE129m,data=df)

I have the message :
Error in parse(file, n, text, prompt) : parse error

 if I change the lab function

lab <- function(i)
 
as.character(paste("italic(phantom(0)^{\"",num[i],"\"}*\"",nom[i],"\")",sep=
""))

text and xyplot work fine if I use the parse function and xYplot works fine.

label(df$GE78) <-  lab(1)
label(df$CS137) <-  lab(2)
label(df$TE129m) <-  lab(3)
plot(1:10)
text(6,6,labels=parse(text=label(df$CS137)))
xyplot(CS137~TE129m,data=df,xlab=parse(text=label(df$CS137)),ylab=parse(text
=label(df$TE129m)))
xYplot(CS137~TE129m,data=df)

What is the good way to use expression in the labels of variables with the
label function ?

thanks




More information about the R-help mailing list