[R] Question about 'text' (add lm summary to a plot)
Gabor Grothendieck
ggrothendieck at gmail.com
Fri Jul 22 19:39:32 CEST 2005
There was an error in the second example. It seems one can use
list in the way wanted in legend but not in text so for text one would
have to use the do.call approach of Thomas or sapply as shown here:
my.slope.1 <- 3.22
my.slope.2 <- 0.13
my.inter.1 <- -10.66
my.inter.2 <- 1.96
plot(1:5)
L <- list(
"Intercept:", bquote(.(my.inter.1)%+-%.(my.inter.2)),
"Slope:", bquote(.(my.slope.1)%+-%.(my.slope.2))
)
text(2, c(4,4,4.25,4.25), sapply(L, as.expression), pos = c(2,4,2,4))
On 7/22/05, Gabor Grothendieck <ggrothendieck at gmail.com> wrote:
> On 7/22/05, Thomas Lumley <tlumley at u.washington.edu> wrote:
> > On Fri, 22 Jul 2005, Dan Bolser wrote:
> >
> > > On Fri, 22 Jul 2005, Gabor Grothendieck wrote:
> > >
> > >> Try as.expression(bquote(...whatever...))
> > >
> > > Sob, wimper, etc.
> >
> > a<-7
> > plot(1)
> > legend("topleft",legend=do.call("expression",
> > list(bquote(alpha==.(a)),bquote(alpha^2+1==.(a^2+1)))))
> >
> > works for me. The trick is getting the inner calls to bquote
> > evaluated, since expression doesn't evaluate its argument.
>
> I think legend accepts a list argument directly so that could be
> simplified to just:
>
> a<-7
> plot(1)
> L <- list(bquote(alpha==.(a)),bquote(alpha^2+1==.(a^2+1)))
> legend("topleft",legend=L)
>
> The same comment seems to apply to my prior suggestion about
> as.expression(bquote(...)), namely that one can just write the
> following as text also supports a list argument:
>
>
> my.slope.1 <- 3.22
> my.slope.2 <- 0.13
> my.inter.1 <- -10.66
> my.inter.2 <- 1.96
>
> plot(1:5)
> L <- list(
> "Intercept:", bquote(.(my.inter.1)%+-%.(my.inter.2)),
> "Slope:", bquote(.(my.slope.1)%+-%.(my.slope.2))
> )
> text(2, c(4,4,4.25,4.25), L, pos = c(2,4,2,4))
>
More information about the R-help
mailing list