Dear all Rhelpers,
Thank you all for quick and helpful response.
Question: How to get the abline lying within the data range?
Suggested solutions:
## 1- base graphics (suggested by Dimitris and Uwe)
x<- rnorm(200, 35,5)
y<- rnorm(200, 0.87,0.12)
plot(y~x, xlim=c(0,55), pch=17, bty="l")
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)
## 2- using ggplot package (by Hadley)
install.packages("ggplot")
library(ggplot)
qplot(x,y, type=c("point","smooth"), method=lm)
#or, if you don't want the standard errors
qplot(x,y, type=c("point","smooth"), method=lm, se=F)
## 3-Using TeachingDemo package (suggested by Greg)
# but I havent try yet
Regards
Nguyen
______________________________________________
[email protected] 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.