On 03/01/2008 6:29 PM, kyselad wrote: > I'm trying to put Greek letters in factor labels on a boxplot. Using the > expression() format works great in axis labels, but seems not to cooperate > when applied to factor labels. More precisely, I'm assigning the labels from > a factor variable using: > > var.order <- ordered(var, levels = c("A", "B"), labels=c(C, D) ) > > Then I create a boxplot with postscript output. If I assign C and D as > quoted text strings, they show up fine as regular text. When I try > expression() for C or D, it chokes. > > Any ideas here? As a potential complication, I need mixed Greek and > non-Greek characters in the labels. Of course, that's easy enough if I can > get expression() working for me. > > Thanks in advance for any suggestions.
You need to use the names=expression() argument to boxplot. There isn't an easy way to save the expressions as factor labels (which must be character values, so you'd need to use parse() to convert them to expressions in the boxplot call), but you can do something like this: x <- rnorm(100) var <- sample(c("A", "B"), 100, rep=TRUE) var.order <- ordered(var, levels=c("A", "B")) boxplot(x ~ var.order, names=expression("C", Delta)) If you really want to attach those expressions to var.order, you could define your own attribute and put them there, e.g. attr(var.order, "namesexpr") <- expression("C", Delta) boxplot(x ~ var.order, names=attr(var.order, "namesexpr")) Be careful what attribute name you use; some of them (e.g. "names") are already used for other purposes. Duncan Murdoch ______________________________________________ R-help@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.