[R] add a linear regression line to the plot
Patrick Connolly
p_connolly at slingshot.co.nz
Thu Jan 13 10:23:50 CET 2011
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
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
More information about the R-help
mailing list