Skip to content

plot color question

2 messages · Derek Margetts, Romain Francois

#
Thanks again Andy and Uwe for you help on my previous
post of ploting lm coef and means.  With your
direction, I was able to expand and generalize the
function to meet my requirements. 

Follow up question: Is it possible to make the points
different colors depending on which quaderant they
fall into?

The data frame contains two variables (x and y)
Quad 1 = x>mean(x) & y>mean(y) would be blue
Quad 2 = x>mean(x) & y<mean(y) would be red
Quad 3 = x<mean(x) & y>mean(y) ....
Quad 4 = x<mean(x) & y<mean(y) ....

Derek
#
Hello

That would do the trick :

x <- rnorm(50)
y <- rnorm(50)
color <- rep("blue",50)
color[(x>0)&(y<0)] <-"red"
color[(x<0)&(y>0)] <-"green"
color[(x<0)&(y<0)] <-"yellow"
plot(x,y,col=color,pch=19)
abline(h=0) #just to check
abline(v=0) #just to check


Romain.

Derek Margetts a ??crit :