[R] How to set Color scale for color2D.matplot()

Jim Lemon jim at bitwrit.com.au
Fri Jul 22 13:57:56 CEST 2011

On 07/22/2011 01:42 AM, Youcheng Lin wrote:
> Hello, everyone.
> I am trying to show the correlation matrix using
> color2D.matplot(). And I want to map (0,1) to (dark red to dark green).
> But by default color2D.matplot() will map(min element of given matrix,
>   max  element of given matrix) to (dark red to dark green).
Hi Youcheng,
If I understand your question, you have a correlation matrix with some 
values below zero, but you want to map only those values greater than or 
equal to zero as dark red - dark green. I'll assume that you want 
another set of colors for the negative values (purple to dark blue). 
Here's how:

cellcolors[corr.matrix >= 0]<-
  color.scale(corr.matrix[corr.matrix >= 0],
cellcolors[corr.matrix < 0]<-
  color.scale(corr.matrix[corr.matrix < 0],

I've included the values in the example so that you can see that the 
positive and negative values are getting the correct colors.


More information about the R-help mailing list