[R] plotting two variables with a third used for color
David Winsemius
dwinsemius at comcast.net
Fri Mar 20 21:23:32 CET 2009
On Mar 20, 2009, at 3:55 PM, Altaweel, Mark R. wrote:
> I have a problem where I have two columns of data that I can simply
> plot using:
>
> plot(wV[0:15,3],wY[0:15,3]).
>
Perhaps:
plot(wV[0:15,3],wY[0:15,3], col = ifelse(wY[0:15,3]>0, "blue","red") )
> 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"
And if they are zero? In my example those become red. Basically you
create a vector that is as long as the y-values with values of "red"
or "blue" that depend on your criterion.
>
>
> 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
>
> else
> 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.
>
> Mark
David Winsemius, MD
Heritage Laboratories
West Hartford, CT
More information about the R-help
mailing list