[R] difficulty with R expressions in text/legend

Murat Tasan mmuurr at gmail.com
Sun Jul 11 02:58:18 CEST 2010


hi, i'm trying to prepend some plain (i.e. unevalutated) text to a
typographically evaluated R expression in a legend(...) call.

here's a working legend(...) call that is close to what i'd like
(where x and y are returned from an lm(...) call):

legend("topleft", legend = c(bquote(R^2 == .(summary(x)$r.squared)),
bquote(R^2 == .(summary(y)$r.squared))), fill = c("blue", "red"))

this evaluates the R^2 values for my x and y objects, then displays
them in the plot legend with colored boxes adjacent to them.

now the hard part (for me, at least :-/), i'd like to add some text
(e.g. "data set 1" and "data set 2") to each line of the legend, right
before the typographically-displayed R^2 == some_value text.

basically, a legend that looks like so (with the expression part
evaluated and typed out correctly):
data set 1 R^2 == some_value
data set 2 R^2 == some_other_value

i've tried a seemingly countless number of paste/substitute/expression
combinations, but cannot seem to get what i'd like.
anyone know of a nice call to create these two strings to display on
my plot?

thanks for any help!

-murat



More information about the R-help mailing list