[R] abline within data range
Dimitris Rizopoulos
dimitris.rizopoulos at med.kuleuven.be
Tue Mar 20 12:49:23 CET 2007
try this:
x <- rnorm(200, 35, 5)
y <- rnorm(200, 0.87, 0.12)
###########
lmObj <- lm(y ~ x)
xs <- range(x)
ys <- predict(lmObj, newdata = data.frame(x = xs))
plot(x, y, pch = 17, bty = "l")
lines(xs, ys, col = "red", lty = 2, lwd = 2)
I hope it helps.
Best,
Dimitris
----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
http://www.student.kuleuven.be/~m0390867/dimitris.htm
----- Original Message -----
From: "Nguyen Dinh Nguyen" <n.nguyen at garvan.org.au>
To: <r-help at stat.math.ethz.ch>
Sent: Tuesday, March 20, 2007 12:32 PM
Subject: [R] abline within data range
> Dear R helpers,
>
> I would like to have abline, for a lm model for
> example, lying within data range. Do you know how to
> get it?
>
> Thank in advance
>
> Nguyen D Nguyen
>
> #CODE
> x<- rnorm(200, 35,5)
> y<- rnorm(200, 0.87,0.12)
> plot(y~x, xlim=c(0,50), pch=17, bty="l")
> abline(lm(y~x))
>
> # I would like abline is between min(x) and max(x)
>
>
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
More information about the R-help
mailing list