[R] Color2D.matplot uniform color range
jalfaro
javier.alfaro.4 at gmail.com
Mon Dec 12 16:15:22 CET 2011
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
An example input csv file is:
aa,A,R,N,D,C,Q,E,G,H,I,L,K,M,F,P,S,T,W,Y,V
A,1.1140,0.9914,0.9706,0.8975,1.0217,1.0151,0.9699,1.0449,1.0126,0.9413,0.9421,0.9766,1.0411,0.9941,0.9243,1.0839,1.1340,0.9732,1.0073,1.0044
R,1.0339,1.0072,0.9642,0.8936,0.9424,0.9915,0.9497,0.9779,0.9896,0.8998,0.9120,0.9646,1.0300,0.9165,0.8856,1.0652,1.0880,0.9213,0.9342,0.9397
N,1.0469,0.9763,1.0613,0.9658,0.9817,0.9640,0.9389,1.0283,1.0294,0.9500,0.9556,0.9869,1.0569,0.9745,0.8287,1.0937,1.0944,0.9701,0.9641,0.9884
D,1.1241,1.0373,1.0358,1.0939,1.0107,1.0260,0.9840,1.0536,1.0727,0.9664,0.9869,1.0481,1.0917,0.9881,0.8351,1.1279,1.1123,0.9908,1.0066,1.0002
C,1.1007,1.0999,1.1280,1.0687,1.1967,1.0964,1.0631,1.1275,1.1668,1.0799,1.0139,1.1009,1.1200,1.0839,0.9009,1.2096,1.2340,1.0837,1.0998,1.1335
Q,1.0078,0.9555,0.9715,0.8813,0.9310,1.0032,0.9339,0.9630,0.9888,0.8811,0.8916,0.9519,0.9993,0.9103,0.8907,1.0625,1.0831,0.9088,0.9300,0.9307
E,1.0494,0.9865,0.9888,0.9247,0.9567,1.0004,1.0270,0.9890,1.0097,0.9088,0.9178,0.9850,1.0252,0.9212,0.8782,1.0737,1.0774,0.9312,0.9447,0.9420
G,0.9900,0.9683,0.9508,0.9162,0.9446,0.9667,0.9472,1.0452,0.9802,0.9247,0.9090,0.9654,0.9940,0.9374,0.8313,1.0343,1.0438,0.9344,0.9401,0.9566
H,1.0022,0.9459,0.9861,0.9343,0.9768,0.9539,0.9241,0.9879,1.0092,0.9259,0.9188,0.9654,1.0090,0.9431,0.8232,1.0544,1.0691,0.9491,0.9503,0.9638
I,1.1463,1.0799,1.0597,1.0151,1.0423,1.0985,1.0570,1.0798,1.0935,1.1005,1.0237,1.0886,1.1383,1.0321,0.8786,1.1389,1.1474,1.0277,1.0343,1.0586
L,1.1444,1.0699,1.0298,0.9750,1.0644,1.0824,1.0402,1.0620,1.0632,1.0042,1.1011,1.0647,1.1253,1.0344,0.9406,1.1156,1.1558,1.0184,1.0373,1.0522
K,1.0350,0.9731,0.9734,0.8856,0.9367,0.9806,0.9329,0.9691,0.9766,0.8962,0.9017,1.0117,1.0164,0.9055,0.8749,1.0328,1.0741,0.9186,0.9302,0.9368
M,1.0612,0.9880,0.9691,0.8914,1.0045,1.0106,0.9690,0.9982,1.0007,0.9349,0.9354,0.9917,1.0036,0.9645,0.9135,1.0471,1.1036,0.9514,0.9740,0.9891
F,1.0519,1.0216,1.0005,0.9571,1.0007,1.0317,0.9909,1.0316,1.0331,0.9821,0.9543,1.0234,1.0531,1.0339,0.8453,1.0861,1.0924,0.9854,0.9858,1.0067
P,0.9846,0.9434,1.0646,1.0543,1.1314,0.9283,0.9357,0.9992,1.0420,0.9883,0.9021,0.9587,0.9830,1.0039,1.0833,1.1387,1.1995,0.9996,1.0210,1.0942
S,0.9851,0.9363,0.9945,0.9485,0.9796,0.9339,0.9174,0.9884,1.0167,0.9337,0.9257,0.9559,1.0246,0.9555,0.8253,1.0447,1.0810,0.9563,0.9570,0.9705
T,0.9587,0.9272,0.9929,0.9602,0.9720,0.9393,0.9115,0.9778,1.0061,0.9354,0.8981,0.9410,0.9701,0.9597,0.7789,1.0650,1.0307,0.9527,0.9650,0.9840
W,1.0231,1.0003,0.9884,0.9447,0.9893,1.0085,0.9943,1.0159,1.0221,0.9541,0.9519,1.0093,1.0434,0.9722,0.8250,1.0622,1.0816,1.0213,0.9804,0.9858
Y,1.0189,1.0075,1.0157,0.9667,1.0037,1.0136,0.9807,1.0238,1.0340,0.9744,0.9282,0.9984,1.0230,0.9903,0.8184,1.0894,1.0973,0.9789,1.0340,1.0086
V,1.0992,1.0823,1.0724,1.0346,1.0629,1.0855,1.0544,1.0968,1.0998,1.0226,0.9972,1.0936,1.1162,1.0423,0.8329,1.1742,1.1807,1.0351,1.0512,1.1072
I'm not seeing the problem here.
Thanks so much Jim.
Jav
--
View this message in context: http://r.789695.n4.nabble.com/Color2D-matplot-uniform-color-range-tp4184701p4186339.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list