Re: [R] plot portion of a line

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Tue 16 Jan 2007 - 17:39:27 GMT

As in Dmitris' post lines is a somewhat more succint so here it is again replacing segments with lines:

set.seed(1)

x <- rnorm(50)
y <- rnorm(50)

plot(y ~ x)

y.lm <- lm(y ~ x)

abline(y.lm) # omit this line if black abline not wanted

x0 <- c(-2, 4)
y0 <- predict(y.lm, list(x = x0))
lines(y0 ~ x0, col = "red", lwd = 2)

On 1/16/07, Gabor Grothendieck <ggrothendieck@gmail.com> wrote:
> Use segments. In the following we overlay the black abline with
> a wider red segments line segment:
>
>
> set.seed(1)
> x <- rnorm(50)
> y <- rnorm(50)
>
> plot(y ~ x)
>
> y.lm <- lm(y ~ x)
>
> abline(y.lm) # omit this line if black abline not wanted
>
> x0 <- c(-2, 4)
> y0 <- predict(y.lm, list(x = x0))
> segments(x0[1], y0[1], x0[2], y0[2], col = "red", lwd = 2)
>
>
>
> On 1/16/07, BBands <bbands@gmail.com> wrote:
> > 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.
> >
>



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 04:53:38 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 - 18:30:32 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.