[R] Color2D.matplot uniform color range

Jim Lemon jim at bitwrit.com.au
Tue Dec 13 12:12:51 CET 2011


On 12/13/2011 02:15 AM, jalfaro wrote:
> Hi Jim,
> Thanks so much for your help. I have read several of your responses on this
> mailing list and they have helped me out quite a bit as I have gotten more
> and more used to R.
>
> I am still a little confused here by your response.
> I think you understood my requirements correctly.
> In your words:
>   I want to anchor the extremes of the scales regardless of the values in the
> matrix.
>   I want 1 color gradient for values between 0 and 1 with a lowerbound cutoff
> at 0.5.
>   I want a second color gradient for values between 1 and infinity with an
> upper bound cutoff at 3.
>
> The function now reads as follows:
>
> make_Q_figure<-function(filename,alias){
>   h0<- read.csv(file=filename,head=TRUE,sep=",",row.names=1)
>   d =data.matrix(h0)
>   cellcolors<-matrix(NA,nrow=20,ncol=20)
>   d<- d[ind,ind]
>   cellcolors[d>= 1&  d<  3]<- color.scale(c(1,3,d[d>= 1&  d<  3]),
> cs1=1,cs2=c(1,0),cs3=c(1,0))[-1:2]
>   cellcolors[d<1]<-
> color.scale(c(0,1,d[d<1]),cs1=c(0,0,1),cs2=c(0,0,1),cs3=1)[-1:2]
>   cellcolors[d>= 2]<-"red"
>
> color2D.matplot(d,cellcolors=cellcolors,show.values=F,na.color="white",axes=FALSE,main=alias,
> xlab="",ylab="")
>   axis(1,at=0.5:19.5,labels=colnames(d))
>   axis(2,at=0.5:19.5,labels=rev(rownames(d)))
> }
>
> However when I execute this function I get the following error:
> Error in color.scale(c(0, 1, d[d<  1]), cs1 = c(0, 0, 1), cs2 = c(0, 0,  :
>    only 0's may be mixed with negative subscripts
Hi Jav,
My fault, the line should read:

color.scale(c(0,1,d[d<1]),cs1=c(0,0,1),cs2=c(0,0,1),cs3=1)[-(1:2)]
  cellcolors[d>= 2]<-"red"

I always forget that the unary minus has precedence over the sequence 
operator.

Jim



More information about the R-help mailing list