PANTERA Laurent wrote:> 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
In Hmisc, labels are used for many contexts in which expressions aren't
allowed, so as of this moment labels must be ordinary character strings.
I typically pass expressions to xYplot using xlab or ylab directly
without using the label.
Frank
>
> ______________________________________________
> R-help at 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
>
--
Frank E Harrell Jr Professor and Chair School of Medicine
Department of Biostatistics Vanderbilt University