Skip to content

plotmath help with expression

2 messages · stephen sefick, Patrick Connolly

#
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)   ?
#
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