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:
corr.matrix<-matrix(runif(100,-1,1),nrow=10)
cellcolors<-matrix(NA,nrow=10,ncol=10)
cellcolors[corr.matrix >= 0]<-
color.scale(corr.matrix[corr.matrix >= 0],
cs1=c(0.7,0),cs2=c(0,0.7),cs3=0)
cellcolors[corr.matrix < 0]<-
color.scale(corr.matrix[corr.matrix < 0],
cs1=c(0.7,0),cs2=0,cs3=0.7)
color2D.matplot(corr.matrix,cellcolors=cellcolors,
show.values=TRUE)
I've included the values in the example so that you can see that the
positive and negative values are getting the correct colors.
Jim