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,
cellcolors=motifx)
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.
color2D.matplot(motifx,na.color="white",cellcolors=motifx+2)
color.legend(0,-15,4,-10,legend=paste(unique(as.vector(motifx)),""),
rect.col=unique(as.vector(motifx)+2))
Jim