[R] add a linear regression line to the plot

Eik Vettorazzi E.Vettorazzi at uke.uni-hamburg.de
Thu Jan 13 14:48:34 CET 2011


Hi,
> lines(lm(x~y),col="red",lwd=1.5)
should be

abline(lm(y~x),col="red",lwd=1.5)

hth.

Am 13.01.2011 09:35, schrieb wangxipei:
>  
> Dear R users,
>    I am a new R user. My problem is very simple: I want to add a linear regression line to the plot(type="p"), codes are as below:
>  
> x<-c(10,20,40,80)
> y<-c(30,40,100,200)
> plot(x,y,type="p")
> lines(lm(x~y),col="red",lwd=1.5)
>  
> I got only plot without linear line.
> Many thanks ahead for your advice!
> 
> Xipei Wang
> E-mail:wangxipei at gmail.com
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> 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.

-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790



More information about the R-help mailing list