[R] plotting two variables with a third used for color

Altaweel, Mark R. maltaweel at anl.gov
Fri Mar 20 20:55:35 CET 2009

I have a problem where I have two columns of data that I can simply plot using:


This produces my desired plot.

Now, say I have a third variable that I would like to introduce and use that variable to set different colors in the plot

In this case, say I wanted values greater than 0 to be "blue" and values less than 0 to be "red"

Basically, my question is how can one plot something like the function shown above, but with the added functionality of indicating color for a third variable

Something to the effect:

if(weightComply[0:15,3]>0)  //if the values from 0 to 15 in column 3 are greater than 0
plot(wV[0:15,3],wY[0:15,3],col="blue")   //then plot the dots as blue 

plot(wV[0:15,3],wY[0:15,3],col="red")  //otherwise plot the dots red

 I know this syntax is wrong, but I think it shows what I generally want to do.


More information about the R-help mailing list