Skip to content
Back to formatted view

Raw Message

Message-ID: <20110113092350.GB4846@slingshot.co.nz>
Date: 2011-01-13T09:23:50Z
From: Patrick Connolly
Subject: add a linear regression line to the plot
In-Reply-To: <1666b43.87c5.12d7e83cb3b.Coremail.wangxipei@gmail.com>

On Thu, 13-Jan-2011 at 04:35PM +0800, wangxipei wrote:

|>  
|> 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!

What about if you tried 
lines(lm(y~x),col="red",lwd=1.5)

My guess is that would be more likely to work.

-- 
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.   
   ___    Patrick Connolly   
 {~._.~}                   Great minds discuss ideas    
 _( Y )_  	         Average minds discuss events 
(:_~*~_:)                  Small minds discuss people  
 (_)-(_)  	                      ..... Eleanor Roosevelt
	  
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.