[R] plot and lm (2)
Antonio Olinto
aolinto at bignet.com.br
Sun Sep 23 20:03:53 CEST 2001
Thanks for your reply Nassar.
What I really want is to overlay (like add=TRUE) the plots 1 and 2. With
plots "at the same screen" I meant overlaid and not one beside the other,
i.e., only one plot with all the points (1 to 10) in blue (or any other
color), the points 5 to 9 in red and a regression line from points 5 to 9.
Best regards,
Antonio Olinto
----- Original Message -----
From: "Rashid Nassar" <rnassar at duke.edu>
To: "Antonio Olinto" <aolinto at bignet.com.br>
Sent: Sunday, September 23, 2001 2:20 PM
Subject: Re: [R] plot and lm
> One way to do this (if I understand you correctly):
>
> > qu
> x y
> 1 1 1.0
> 2 2 2.0
> 3 3 3.0
> 4 4 4.0
> 5 5 4.4
> 6 6 4.1
> 7 7 3.2
> 8 8 3.1
> 9 9 2.4
> 10 10 2.7
>
> > qu$group <- c(rep(1,4),rep(2,5), 1)
> > attach(qu)
> > opar <- par(mfcol=c(1,2), pty="s") # use pty="m" (default) if you
> #don't want square plots.
> > plot(x,y, col="blue", pch=19)
> > title("Plot 1")
> > plot(x[group==2], y[group==2], col="red", pch=19, main="Plot 2")
> > abline(lm(y ~ x, data=qu, subset=group==2), col="red")
> > detach(qu)
> > par(opar)
>
>
> I hope this helps.
>
> Rashid Nassar
>
> On Sun, 23 Sep 2001, Antonio Olinto wrote:
>
> > Date: Sun, 23 Sep 2001 13:16:46 -0300
> > From: Antonio Olinto <aolinto at bignet.com.br>
> > To: R-help <r-help at stat.math.ethz.ch>
> > Subject: [R] plot and lm
> >
> > Hello R-list,
> >
> > I'm trying to make a scatter plot with two dependent variables and a
> > regression line only for one "y", but I'm having some problems. Well, I
will
> > explain better what I'm doing - it's a method used to estimate the total
> > mortality rate in fish stocks.
> >
> > Suppose a I have the following data (dat):
> >
> > > dat
> > x y
> > 1 1 1.0
> > 2 2 2.0
> > 3 3 3.0
> > 4 4 4.0
> > 5 5 4.4
> > 6 6 4.1
> > 7 7 3.2
> > 8 8 3.1
> > 9 9 2.4
> > 10 10 2.7
> >
> > With plot(x,y col="blue", pch=19) and identify(x,y) I can identify the
blue
> > points that follow a descendent trend (negative slope). They are points
5 to
> > 9. Let's call this plot 1.
> >
> > With dat2 <- dat[c(5:9),] I can make another data.frame and and using
> > attach(dat2), plot(x,y, col="red", pch=19), reg <- lm(y~x) and
abline(reg) I
> > have another plot (plot 2) with red points and the regression line.
> >
> > I would like to have in one plot all the points (1 to 10) in blue, the
> > points 5 to 9 in red and a regression line from points 5 to 9. In other
> > words, plots 1 and 2 at the same screen. I'm sure that it's possible to
do
> > this plot but after several attempts I decide to ask for your help in
this
> > Sunday morning.
> >
> > Thanks for any suggestion,
> >
> > Antonio Olinto
> > Fisheries Institute
> > Sao Paulo - BRAZL
> >
> >
>
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
-.-.-
> > r-help mailing list -- Read
http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> > Send "info", "help", or "[un]subscribe"
> > (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
> >
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
_._
> >
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list