Hi Aimin, This example uses a log transformation to spread the colors out: d<-read.table(text=" lateRT earlyRT NAD ciLAD LAD 1.000000000 0.0000000000 0.006224017 0.001260241 0.0069699285 0.000000000 1.0000000000 0.001425649 0.007418436 0.0007096344 0.006224017 0.0014256488 1.000000000 0.064653780 0.3935566356 0.001260241 0.0074184361 0.064653780 1.000000000 0.0024839407 0.006969928 0.0007096344 0.393556636 0.002483941 1.0000000000", header=TRUE) rownames(d)<-colnames(d) d<-as.matrix(d) diag(d)<-NA library(plotrix) color2D.matplot(-log(d+0.0001),extremes=c("red","blue"), main="Correlation matrix of d",axes=FALSE) axis(1,at=seq(0.5,4.5),labels=colnames(d)) axis(2,at=seq(0.5,4.5),labels=rownames(d)) color.legend(0,-0.7,2,-0.5,legend=c(0,0.001,0.007,0.07,0.4), rect.col=color.scale(log(c(0.00001,0.001,0.005,0.07,0.4)), extremes=c("blue","red")),align="rb")
Jim On Thu, Feb 28, 2019 at 2:52 PM Aimin Yan <aimin.at.w...@gmail.com> wrote: > > I have a question about assigning color based on the value of a matrix > > The following is my matrix. > > d > lateRT earlyRT NAD ciLAD > lateRT 1.000000000 0.0000000000 0.006224017 0.001260241 > earlyRT 0.000000000 1.0000000000 0.001425649 0.007418436 > NAD 0.006224017 0.0014256488 1.000000000 0.064653780 > ciLAD 0.001260241 0.0074184361 0.064653780 1.000000000 > LAD 0.006969928 0.0007096344 0.393556636 0.002483941 > LAD > lateRT 0.0069699285 > earlyRT 0.0007096344 > NAD 0.3935566356 > ciLAD 0.0024839407 > LAD 1.0000000000 > > I want to use the following function to get heatmap and dendrogram > > > heatmap.2(d,trace="none",margin=c(8, 10)) > > but it is hard to use color to make 0.001260241 and 0.0074184361 to be > visualized differently. > > Does anyone know how to adjust color based on these values in this matrix? > > Thank you, > > Aimin > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.