# [R] Scatter Plot in R - Help

J.delasHeras at ed.ac.uk J.delasHeras at ed.ac.uk
Fri Apr 27 19:26:17 CEST 2007

```Quoting A Ezhil <ezhil02 at yahoo.com>:

> Dear All,
>
> I am using the following commands to do the scatter
> plot of two vectors, say X and Y.
>
> plot(X,Y, col="blue")
> abline(a=1,b=1, col="red")
> abline(a=-1,b=1, col="green")
>
> I would like to split the scatter plot into 3 part
> with 3 different colors: (i) points lies between 2
> lines, (ii) points above line 1, and (iii) points
> below line 2. I am struggling to do this. I would
> greatly appreciate any help in doing this.
>
>
> Kind regards,
> Ezhil

check ?points

'points' allows you to plot points using different plotting parameters
(type, size, colours...).
You can subset the points in your scatter plot into three groups, and
use 'points' on each group separately.

For instance:

x<-sample(c(-10:10),size=21)
y<-sample(c(-10:10),size=21)
plot(x,y, col="blue",pch=16)
abline(a=1,b=1, col="red")
abline(a=-1,b=1, col="green")
# then find the red and green groups:
reds<-which(y>x+1)
greens<-which(x>y+1)
points(x[reds],y[reds], col="red",pch=16)
points(x[greens],y[greens], col="green",pch=16)

you could also choose to not plot anything at first (use parameter
type="n"), and define not just the red and green groups, but also teh
blue ones too. You may need to do this if you want to use different
plotting characters or sizes and overplotting doesn't look good.

Jose

--
Dr. Jose I. de las Heras                      Email: J.delasHeras at ed.ac.uk
The Wellcome Trust Centre for Cell Biology    Phone: +44 (0)131 6513374
Institute for Cell & Molecular Biology        Fax:   +44 (0)131 6507360