[R] plotmath help with expression

Patrick Connolly p_connolly at slingshot.co.nz
Wed Sep 3 22:13:16 CEST 2008


On Wed, 03-Sep-2008 at 02:18PM -0400, stephen sefick wrote:

|> reg.line <- function(y, x, title)
|> {plot(y~x, main=title, xlab="TSS", ylab="Aluminum")
|> line <- lm(y~x)
|> d <- summary(line)
|> legend("topleft", legend=paste(expression(r^2), "=" ,d$r.squared,
|> sep=" "), bty="n")
|> abline(line)}
|> 
|> reg.line(1:10, 10:1, "line")
|> 
|> how do I get the legend to print the plotmath symbol expression(r^2)   ?

I think you want your 'paste' part to look something like this:

legend = substitute(r^2 == rsq, list(rsq = d$r.squared))


It's quite a different approach from what is used with paste.

HTH
-- 
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.   
   ___    Patrick Connolly   
 {~._.~}          		 Great minds discuss ideas    
 _( Y )_  	  	        Middle minds discuss events 
(:_~*~_:) 	       		 Small minds discuss people  
 (_)-(_)  	                           ..... Anon
	  
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.



More information about the R-help mailing list