[R] plot and lm

Antonio Olinto aolinto at bignet.com.br
Sun Sep 23 18:16:46 CEST 2001

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

More information about the R-help mailing list