Re: [R] Adding info from summary(lm(...)) to plot

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Sun, 9 Dec 2007 14:32:54 -0500

If x <- round(...whatever...) try:

title(capture.output(print(x)))

On Dec 9, 2007 2:15 PM, Ted Harding <Ted.Harding_at_manchester.ac.uk> wrote:
> Hi Folks,
>
> Say I have 2 continuous variables X,Y.
>
> I can of course plot (X,Y) with
>
> plot(X,Y,pch="+",col="blue")
>
> say, and add the regression line from lm(Y~X)
> by extracting the coefficients 'a' of Intercept
> and 'b' of X from Y.lm <- lm(Y~X).
>
> Now, however, I want to have not only a general
> explanatory title such as
>
> main="Plot of Y against X"
>
> but also (and ideally just under the main title
> and above the figure region of the plot) the
> result of
>
> round(summary(Y.lm)[[4]],digits=3)
>
> exactly as shown below:
>
> Estimate Std. Error t value Pr(>|t|)
> (Intercept) 78.636 0.273 287.902 0.000
> X -0.074 0.029 -2.527 0.012
>
> It would also be OK to have it as a "subtitle"
> below the xlabel (which by default is X" in this case).
>
> I've been trying to work out how to so this simply,
> but without much success. I can see a complicated
> way, which involves binding the row and column names,
> and the values, of the above output, using paste()
> along with "\n" at suitable places, but I'd like to
> have something much less intricate than that!
>
> I'd also like to be able to integrate the solution
> nicely with the main title (or the X label) so that
> there's no overlap.
>
> Any suggestions?
>
> with thanks,
> Ted.
>
> --------------------------------------------------------------------
> E-Mail: (Ted Harding) <Ted.Harding_at_manchester.ac.uk>
> Fax-to-email: +44 (0)870 094 0861
> Date: 09-Dec-07 Time: 19:15:08
> ------------------------------ XFMail ------------------------------
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sun 09 Dec 2007 - 19:39:39 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 09 Dec 2007 - 20:30:18 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.