[R] Color2D.matplot uniform color range
jalfaro
javier.alfaro.4 at gmail.com
Mon Dec 12 04:48:25 CET 2011
Hi all.
I am having a problem using color2D.matplot
I am trying to visualize several different matrices under two color ranges.
One color range corresponds to values less than 1 and the second color range
for values greater than 1. However, the minimum value of each matrix differs
and is automatically set to have the smallest value in the color range.
Similarly, the maximum value of each matrix differs leading to non-uniform
color scales.
Below is the function that is causing me trouble. It is designed to take as
input 2 csv files with row and column headers describing a 20X20 matrix.
The goal would be to modify the code below as follows.
(1) if an entry is in range [0,1] the color scale should always be uniform
with the minimum color being 0.5 and the maximum color being 1.
(2) if an entry is in the range [1,infinity] the color scale should have
minimum color value 1 and maximum color value 3. (I used infinity simply
because there is no way of knowing how high the value will be beforehand).
Any help would be greatly appreciated.
Thanks,
Jav
library(plotrix)
make_S_figure<-function(filename,alias){
h0 <- read.csv(file=filename,head=TRUE,sep=",",row.names=1)
d =data.matrix(h0)
m <- 1:20
cellcolors<-matrix(NA,nrow=20,ncol=20)
cellcolors2<--matrix(NA,nrow=20,ncol=20)
for(i in 1:length(m)){
cellcolors[d >= 1]<-color.scale(d[d>=1],cs1=c(1,1),cs2=c(1,0),cs3=c(1,0))
cellcolors[d<1]<-color.scale(d[d<1],cs1=c(0,1),cs2=c(0,1),cs3=c(1,1))
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)))
}
--
View this message in context: http://r.789695.n4.nabble.com/Color2D-matplot-uniform-color-range-tp4184701p4184701.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list