xin wei
2010-May-12 15:57 UTC
[R] what the problem could be if i am suddenly unable to add abline to the scatter plot?
I am doing very regular stuff like the following: attach(wtana) fm<- lm(Body.Wt.on.SD1~Heart.Wt, data=wtana) #fm<- lm(wtana$Body.Wt.on.SD1~wtana$Heart.Wt) lrf<- loess(Body.Wt.on.SD1~Heart.Wt, wtana) #lrf<- loess(wtana$Body.Wt.on.SD1~wtana$Heart.Wt) plot(Body.Wt.on.SD1,Heart.Wt) #plot(wtana$Body.Wt.on.SD1,wtana$Heart.Wt) #lines(spline(Heart.Wt,fitted(lrf)), col=2) abline(fm, col=4) however, the abline just refuse to to show up in the scatter cloud. Does anyone has clue? thanks -- View this message in context: http://r.789695.n4.nabble.com/what-the-problem-could-be-if-i-am-suddenly-unable-to-add-abline-to-the-scatter-plot-tp2196304p2196304.html Sent from the R help mailing list archive at Nabble.com.
David Winsemius
2010-May-12 17:16 UTC
[R] what the problem could be if i am suddenly unable to add abline to the scatter plot?
On May 12, 2010, at 11:57 AM, xin wei wrote:> > I am doing very regular stuff like the following: > > > attach(wtana) > > fm<- lm(Body.Wt.on.SD1~Heart.Wt, data=wtana) > #fm<- lm(wtana$Body.Wt.on.SD1~wtana$Heart.Wt) > lrf<- loess(Body.Wt.on.SD1~Heart.Wt, wtana) > #lrf<- loess(wtana$Body.Wt.on.SD1~wtana$Heart.Wt) > > plot(Body.Wt.on.SD1,Heart.Wt) > #plot(wtana$Body.Wt.on.SD1,wtana$Heart.Wt) > #lines(spline(Heart.Wt,fitted(lrf)), col=2) > abline(fm, col=4) > > however, the abline just refuse to to show up in the scatter cloud. > Does anyone has clue?I don't know that abline has a method for lm objects. > methods(abline) no methods were found Warning message: In methods(abline) : function 'abline' appears not to be generic Have you tried using coef(lm) as your argument to abline? (Untested in the absence of a cut-and-pastable example.)> thanks-- David Winsemius, MD West Hartford, CT
Daniel Malter
2010-May-12 17:38 UTC
[R] what the problem could be if i am suddenly unable to add abline to the scatter plot?
Xin, you plot the scatterplot wrongly. Note that the lm (your OLS regression) has a wiggle, whereas you plot command has a comma. The plot command also should have a wiggle so that you plot y against x and not x against y. See example below: x=rnorm(100);e=rnorm(100) y=2*x+e reg=lm(y~x) par(mfcol=c(1,2)) #This is wrong) plot(y,x) abline(reg) #This is right plot(y~x) abline(reg) -- View this message in context: http://r.789695.n4.nabble.com/what-the-problem-could-be-if-i-am-suddenly-unable-to-add-abline-to-the-scatter-plot-tp2196304p2196469.html Sent from the R help mailing list archive at Nabble.com.
Daniel Malter
2010-May-12 17:49 UTC
[R] what the problem could be if i am suddenly unable to add abline to the scatter plot?
Just a quick addendum: You actually plot the line. If it is not in the graph then just because it is outside the limits of the plotting region. But since it's the right line on the wrong plot, it does not matter anyway. You need to get the plot right first, which you do in the way I described above. Daniel -- View this message in context: http://r.789695.n4.nabble.com/what-the-problem-could-be-if-i-am-suddenly-unable-to-add-abline-to-the-scatter-plot-tp2196304p2196489.html Sent from the R help mailing list archive at Nabble.com.