Skip to content
Prev 247220 / 398503 Next

add a linear regression line to the plot

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.