Skip to content
Back to formatted view

Raw Message

Message-ID: <4D2F02B2.4020100@uke.uni-hamburg.de>
Date: 2011-01-13T13:48:34Z
From: Eik Vettorazzi
Subject: add a linear regression line to the plot
In-Reply-To: <1666b43.87c5.12d7e83cb3b.Coremail.wangxipei@gmail.com>

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