[R] color2D.matplot not giving colors

Jim Lemon jim at bitwrit.com.au
Sun Mar 7 09:18:17 CET 2010

On 03/07/2010 05:23 AM, david hilton shanabrook wrote:
> I am using color2D.matplot to plot a matrix about 400 by 200.
> The values in the matrix are 0:5 and NA.  The resulting plot is not color, but shaded b/w.  I tried to figure out how to add colors, I would like something like c(blue, green, red, cyan, green)
> #example
> motifx<- matrix(NA, nrow=100,ncol=20)
> motifx[,1:5]<- 1
> motifx[,6:10]<- 2
> motifx[,11:15]<- 3
> motifx[,15:19]<- 4
> motifx
> color2D.matplot(motifx, na.color="white",show.legend=TRUE)
> or is there a better function to use than color2D.matplot?

Hi David,
The reason you are not getting colors is because you are not asking for 
them. The default behavior is to translate the numbers in "motifx" into 
grayscale in which black and white are equivalent to min(motifx) and 
max(motifx) respectively. What you may want is this:

color2D.matplot(motifx, na.color="white",show.legend=TRUE,

but your legend will be incorrect, as the automatic legend function 
tries to scale the colors into range(motifx). If you are going to supply 
the cellcolors, it is best to use color.legend to display the legend, as 
you know that the number of unique colors is small, e.g.



More information about the R-help mailing list