[R] color2D.matplot

Jim Lemon jim at bitwrit.com.au
Wed Nov 7 13:13:15 CET 2007

wragbag wrote:
> I am a true R novice aonly using it for this function ;)
> I am trying to use color2D.matplot to form a image of my data using the
> following conditions
> color2D.matplot(fi1, c(dr), c(dg), c(db), nslices=7, ylab='Species',
> xlab="gene", show.legend=TRUE) where fi1 is my matrix.
> I have a matrix with 36 columns and 130 rows. most entries are 1 or 0 and I
> am trying to get this function to plot these as either 0 = white or 1 =
> black. This is fine but one column contains entries between 0 and 7. I would
> entries between 2 and 7 to be different colors (as this is what I am trying
> to show although I also need to see the black and white areas) using the
> following:
>>dr = c(1,0,1,0,0)
>>dg = c(1,0,0,1,0)
>>db = c(1,0,0,0,1)
> I can get some color to work but I cannot get them all as if I but in a c()
> range equalling 0-7 (i.e. one color for each number I get the following. I
> cannot figure out from the documentation why it will not let me do what I
> want :(
> Error in rescale(x[segindex], redrange[c(seg, seg + 1)]) : 
>   rescale: can't rescale a constant vector!
Hi wragbag,
This is a situation that I had not envisaged in the design of 
color2D.matplot. However, I think there is a workaround.


Because of the unusual way of specifying the color ranges to
get white, black and then six colors, the rescale function
throws an error on the constant vectors it is asked to rescale.
I may have to think whether I can make it deal with this
situation more gracefully. However, the above will get your
plot and you can specify whatever colors you wish for the last
six values in each primary color range. (What I have done is to
specify as many color ranges as there are values).


More information about the R-help mailing list