[R] Lattice: key with expression function

Folkes, Michael FolkesM at pac.dfo-mpo.gc.ca
Wed Sep 5 22:56:12 CEST 2007


Thanks to Deepayan...again, for suggesting "parse".
Here is how I added the degree symbol to a vector of text for my xyplot
legend:

auto.key =list(points = FALSE,text=parse(text =
paste(levels(as.factor(divertSST2$temp)), "*degree", sep = ""))), 

For me the tricky part was learning about adding the '*'.  I found that
in this suggestion:
http://finzi.psych.upenn.edu/R/Rhelp02a/archive/78961.html

Michael Folkes

-----Original Message-----
From: deepayan.sarkar at gmail.com [mailto:deepayan.sarkar at gmail.com] 
Sent: September 5, 2007 11:27 AM
To: Folkes, Michael
Cc: r-help at stat.math.ethz.ch
Subject: Re: [R] Lattice: key with expression function


On 9/5/07, Folkes, Michael <FolkesM at pac.dfo-mpo.gc.ca> wrote:
> HI all,
> I'm trying (unsuccessfully) to add the degree symbol to each line of 
> text in my legend (within xyplot). Here is the line of code, which 
> fails to interpret the expression
> function:
>
> auto.key =list(points = 
> FALSE,text=paste(levels(as.factor(divertSST2$temp)),expression(degree)
> ).
> ..),
>
> I just get:
> 7 degree
> 8 degree
> 9 degree

That's because

> paste("foo", expression(degree))
[1] "foo degree"


> If I place 'expression' outside or just after the paste function it 
> also doesn't work.

auto.key = list(text = expression(paste("foo", degree)))

should work. I think the problem is that you want a vector of
expressions, and that's a bit harder to get. I'm not sure what the best
solution is, but if everything else fails, you could try using
parse(text=)

-Deepayan



More information about the R-help mailing list