[R] plot/lm/abline

Duncan Murdoch murdoch at stats.uwo.ca
Thu Jun 2 15:34:04 CEST 2005


Mathias Hunskår Furevik wrote:
> Hi,
> 
> when I run
> 
> 
>>plot.default(z1, z2, xlab = "x", ylab = "y", main = "xxxx", pch = "+")
>>abline(lm(z1 ~ z2))
> 
> 
> then the plot is plotted perfectly (scatterplot), however, the lm()
> function doesnt appear on the plot. What could be wrong?
> 
> (Yesterday it worked perfectly, with the lm() line.)

You've reversed the order of variables.  Try

abline(lm(z2 ~ z1))

Plot takes variables in the order x, y.

lm takes variables in the order y ~ x.

Duncan Murdoch




More information about the R-help mailing list