[R] Array of legend text with math symbols from predefined variables

Koen koen666 at hotmail.com
Fri Dec 11 13:46:18 CET 2009


Hello,

I am trying to include legend text with math symbols from a predefined
character variable that is read in from a file.
 
If there is only one line of text in the legend, the following, although
cumbersome, works for me:

  > LegendText = " 'U' [infinity], '=10 m/s' "   # (read in from a file)
  > LegendName = paste("bquote(paste(",LegendText, "))")
  > plot( c(1,2,3), c(1,2,3) )
  > legend(‘topleft’,1, eval(parse(text=LegendName)) ) 

 If I now have more than one line in a plot and hence want to include more
than one line of legendtext, I run into problems because

  > legend(‘topleft’,1, c(
 eval(parse(text=LegendName1)),eval(parse(text=LegendName2))  ) 

will not result in evaluation of the character string but just a paste of
the string and

  > legend(‘topleft’,1, eval(parse(text=c(LegendName1, LegendName2)))  ) 

will only evaluate the first element of the array.

Am I trying to do the impossible or is my approach totally wrong? Any help
would be greatly appreciated!

Koen




More information about the R-help mailing list