[R] How to use expression in label with xYplot

From: PANTERA Laurent <laurent.pantera_at_irsn.fr>
Date: Wed 22 Jun 2005 - 17:14:03 EST


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



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed Jun 22 17:17:41 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:56 EST