[R] abline within data range

hadley wickham h.wickham at gmail.com
Tue Mar 20 19:54:37 CET 2007


On 3/20/07, Nguyen Dinh Nguyen <n.nguyen at garvan.org.au> wrote:
> 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))

This is really easy with ggplot:

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)

Hadley



More information about the R-help mailing list