[R-sig-Geo] Adding R-square to linear regression

Rob Robinson rob.robinson at bto.org
Fri Jul 20 14:01:58 CEST 2007


Thomas,
 Can you not use text() to add a label? If you are using lm() to generate
the regression you can get at the R.sq by calling summary:
summary(c)$r.squared [there's also an adj.r.squared, have a look at
summary.lm]
So something along the lines of
text(x=xpos,y=ypos,summary(obj)$r.squared)
ought to work, see code below
Hth
rob


a=c(1,2,3,4,5)
b=c(1,3,2,5,4)
c=lm(a~b)
summary(c)$r.squared
plot(a~b)
text(x=2,y=2,summary(c)$r.squared)

*** Want to know about Britain's birds? Try  www.bto.org/birdfacts ***

Dr Rob Robinson, Senior Population Biologist
British Trust for Ornithology, The Nunnery, Thetford, Norfolk, IP24 2PU
Ph: +44 (0)1842 750050         E: rob.robinson at bto.org
Fx: +44 (0)1842 750030         W: http://www.bto.org
eSafe scanned this email for viruses, vandals and malicious content (!)

==== "How can anyone be enlightened, when truth is so poorly lit" =====
  

> -----Original Message-----
> From: r-sig-geo-bounces at stat.math.ethz.ch 
> [mailto:r-sig-geo-bounces at stat.math.ethz.ch] On Behalf Of 
> Thomas Szegvary
> Sent: 20 July 2007 12:39
> To: r-sig-geo at stat.math.ethz.ch
> Subject: [R-sig-Geo] Adding R-square to linear regression
> 
> Dear R users
> 
> I want to produce scatter plots from the following data set, 
> using R 2.5.0
> 
> summary(comps)
> OBS           TM5_STAND      
> Min.   :  0.250   Min.   : 4.223 
> 1st Qu.:  2.440   1st Qu.: 5.539 
> Median :  3.936   Median : 6.449 
> Mean   :  4.475   Mean   : 6.748 
> 3rd Qu.:  5.790   3rd Qu.: 7.637
> Max.   : 13.283   Max.   :15.452
> 
> A simple scatter plot, where I added a linear regression. 
> Here is the code:
> 
> plot(comps$OBS,comps$TM5_STAND,xlab="observation",ylab="222-Rn
> model",main="TM5_STAND")
> abline(lm(comps$TM5_STAND ~ comps$OBS,data=comps))
> 
> But as i have to do this for a lot of datasets, I want to 
> compare the R-square and therefore would like to add the 
> R-Square to the plot automatically. I have checked faq and a 
> lot of r-sig-geo messages but haven't found a solution, for 
> this I think trivial problem.
> 
> Does someone knows a code for this?
> Many thanks
> 
> Thomas
> 
> __
> 
> Thomas Szegvary
> Institute of Environmental Geosciences
> Department of Geosciences
> University of Basel
> Bernoullistrasse 30
> CH - 4056 Basel
> 
> Tel.  41-61-267 04 82
> Fax. 41-61-267 04 79
> Email: t.szegvary at unibas.ch
> www.radon.unibas.ch
> www.unibas.ch/environment
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>




More information about the R-sig-Geo mailing list