Hi,
if it should be "lines" so you can do that
xy.lm <- lm(y~x)
lines(x, xy.lm$coeff[1] + x*xy.lm$coeff[2], col="blue", lwd=3)
Regards
ep
--
View this message in context:
http://r.789695.n4.nabble.com/add-a-linear-regression-line-to-the-plot-tp3215455p3216099.html
Sent from the R help mail
Hi,
> lines(lm(x~y),col="red",lwd=1.5)
should be
abline(lm(y~x),col="red",lwd=1.5)
hth.
Am 13.01.2011 09:35, schrieb wangxipei:
>
> 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(1
?abline
On Thu, Jan 13, 2011 at 12:29 AM, wo 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",l
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
Such things are very easy with the ggplot2 package
install.packages("ggplot2")
library(ggplot2)
Dataset <- data.frame(A = c(10,20,40,80), B = c(30,40,100,200))
ggplot(data = Dataset, aes(x = A, y = B)) + geom_point() +
geom_smooth(method = "lm")
More info and example on the ggplot2 website: http:
5 matches
Mail list logo