[R] abline within data range

Uwe Ligges
Tue, 20 Mar 2007 11:56:48 -0000

Nguyen Dinh Nguyen 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))
>
> # I would like abline is between min(x) and max(x)

Just make it yourself as in:

  newdat <- data.frame(x = range(x))
  pred <- predict(lm(y ~ x), newdata = newdat)
  lines(newdat$x, pred)

Uwe Ligges




>
>
>
>
> 	[[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