[R] math symbols in plot legend

Bill.Venables@cmis.csiro.au Bill.Venables at cmis.csiro.au
Wed May 8 10:05:02 CEST 2002


Ott Toomet asks:

>  -----Original Message-----
> From: 	Ott Toomet [mailto:siim at obs.ee] 
> Sent:	Wednesday, May 08, 2002 5:12 PM
> To:	r-help at stat.math.ethz.ch
> Subject:	[R] math symbols in plot legend
> 
> Hi,
> 
> I have tried to include a description into legend which includes
> mathematical symbols and actual values.  Basically, I want something like
> 
> > legend(0.5,1,
> 	legend=c(expression(gamma==0.2), 
> 		expression(gamma==1), 	
> 		expression(gamma==5)), 
> 	lty=1:3)
> 
> Where gamma should be the greek letter.
> 
> The problem is that the actual numeric values can change and the number of
> expressions can change too.  I have tried to build a vector of expressions
> something like
> 
>   leg <- NULL
>   for(i in seq(along=g)) {
>     leg <- c(leg, substitute(expression(gamma==gam), list(gam=g[i])))
>   }
> 
> but this results into a list and not vector of expressions (however,
> component expressions are correct).  My attempts to
> convert it with as.expressions() and similar are not been fruitful so
> long.
	[WNV]  Here is a possibility:

	> g <- c(0.2, 1, 5)
	> leg <- expression()
	> for(h in g) leg <- c(leg, substitute(expression(gamma == gam),
list(gam = h))[[2]])
	> leg
	expression(gamma == 0.2, gamma == 1, gamma == 5)

	For comparison, here is what you were using directly:

	> c(expression(gamma == 0.2), expression(gamma == 1),
expression(gamma == 5))
	expression(gamma == 0.2, gamma == 1, gamma == 5)

	The curious question is why is the [[2]] necessary in the
substitute() statemene above?  
	Ah, that would be telling!

	W.

> I am using R 1.4.0 on linux.
> 
> Any suggestions?
> 
> Ott Toomet
> 
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
> -.-.-
> r-help mailing list -- Read
> http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
> _._._
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list