Re: [R] plot portion of a line

From: Dimitris Rizopoulos <dimitris.rizopoulos_at_med.kuleuven.be>
Date: Tue 16 Jan 2007 - 16:32:06 GMT

you could try something like the following:

x <- rnorm(50)
y <- rnorm(50)
obj <- lm(y ~ x)

par(mfrow = c(2, 2))
plot(x, y, main = "x < -1")
x. <- c(min(x), -1)
y. <- predict(obj, data.frame(x = x.))
lines(x., y.)

plot(x, y, main = "x > 1")
x. <- c(1, max(x))
y. <- predict(obj, data.frame(x = x.))
lines(x., y.)

plot(x, y, main = "x > -1 & x < 1")
x. <- c(-1, 1)
y. <- predict(obj, data.frame(x = x.))
lines(x., y.)

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


> Dear HelpeRs,
>
> Given:
> x <- rnorm(50)
> y <- rnorm(50)
> plot(x,y)
> abline(lm(x ~ y))
>
> Is there a way to plot just a portion of the line? Say for values of
> x
>> 2.0 or x > -2.0 and x < 4.0. (Still fitting all the points.)
>
> Thank you,
>
> jab
> --
> John Bollinger, CFA, CMT
> www.BollingerBands.com
>
> If you advance far enough, you arrive at the beginning.
>
> ______________________________________________
> R-help@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



R-help@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. Received on Wed Jan 17 03:38:06 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 16 Jan 2007 - 17:30:27 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.