Dear All, I am using the plotrix library to plot some matrices. I have a problem: some of my data are outliers, hence using a linear color scale does not work very well (you would see too many cells having a similar, indistinguishable color). See the code snipped at the end of the email. Plotting the logarithm of the data gets the job done, but my problem is that I would like to write in every cell the value of the corresponding entry of the original matrix, not is logarithm. Does anyone know how to get this done? Or the other way around: leave the data as is, but use a color log scale. Many thanks Lorenzo library(plotrix) set.seed(1234) myseq <- abs(rnorm(25)) myseq[20] <- 100 #introduce outlier! A <- matrix(myseq, ncol=5,nrow=5) #nasty looking figure pdf("test_color_scale.pdf") oldpar<-par( mar = c(4.5,5, 2, 1) + 0.1, cex.axis=1.4,cex.lab=1.6,cex.main=1.6) color2D.matplot(A,main="Title",c(0.2,1),c(0.2,0.5),c(0,0), xlab = "", ylab="", show.legend=TRUE, show.values=1,vcol="black",vcex=1, axes=FALSE) ## axis(1,at=c(0.5,1.5,2.5,3.5,4.5),labels=prefix_vec_short) ## axis(2,at=rev(c(0.5,1.5,2.5,3.5,4.5)),labels=prefix_vec_short) box() par(oldpar) dev.off() #this looks better, but in each cell I would like to see the same #numbers as before. pdf("test_color_scale_log.pdf") oldpar<-par( mar = c(4.5,5, 2, 1) + 0.1, cex.axis=1.4,cex.lab=1.6,cex.main=1.6) color2D.matplot(log(A),main="Title",c(0.2,1),c(0.2,0.5),c(0,0), xlab = "", ylab="", show.legend=TRUE, show.values=1,vcol="black",vcex=1, axes=FALSE) ## axis(1,at=c(0.5,1.5,2.5,3.5,4.5),labels=prefix_vec_short) ## axis(2,at=rev(c(0.5,1.5,2.5,3.5,4.5)),labels=prefix_vec_short) box() par(oldpar) dev.off()

On Wed, Jun 23, 2010 at 10:01 AM, Lorenzo Isella <lorenzo.isella at gmail.com> wrote:> Dear All, > I am using the plotrix library to plot some matrices. > I have a problem: some of my data are outliers, hence using a linear > color scale does not work very well (you would see too many cells having > a similar, indistinguishable color). See the code snipped at the end of > the email. > Plotting the logarithm of the data gets the job done, but my problem is > that I would like to write in every cell the value of the corresponding > entry of the original matrix, not is logarithm. > Does anyone know how to get this done? Or the other way around: leave > the data as is, but use a color log scale. > Many thanksHi Lorenzo, I'm not sure about plotrix, but the WGCNA package contains a function called labeledHeatmap which allows you to specify the color matrix and the text matrix separately. I'm the author of the package and of the function. The WGCNA package is not on CRAN yet, but you can download it from http://www.genetics.ucla.edu/labs/horvath/CoexpressionNetwork/Rpackages/WGCNA/ Look at the help file for labeledHeatmap for some examples. The arguments are a bit arcane because I wrote the first version with a very particular use in mind and then kept it for compatibility, but you will find your way around. Peter

Lorenzo, This is a bit ugly but should work. Instead of using plotrix's show.values, use the text() command: for(i in 1:5) { for(j in 1:5) { text(i-0.5,j-0.5,format(A[6-j,i],digits=3),col="white") } } -- View this message in context: http://r.789695.n4.nabble.com/Plotrix-Trick-tp2265893p2266390.html Sent from the R help mailing list archive at Nabble.com.

Lorenzo, You can also use a custom colorscale using color.scale and the cellcolors option of color2D.matplot: pdf("test_color_scale_logcolor.pdf") oldpar<-par( mar = c(4.5,5, 2, 1) + 0.1, cex.axis=1.4,cex.lab=1.6,cex.main=1.6) cellcolors <- color.scale(log(A),c(0.2,1),c(0.2,0.5),c(0,0)) color2D.matplot(A,main="Title", cellcolors=cellcolors, xlab = "", ylab="", show.legend=TRUE, show.values=1,vcol="black",vcex=1, axes=FALSE) box() par(oldpar) dev.off() Regards, Jan

Dear Hrishi, I am almost there, thanks. The only small problem left is to convince also the colorbar to plot the values I want. Consider the small snippet at the end of the email: colors and numbers inside the cells are OK, but the legend shows the extremes of the log transformed data instead of the original one. Any suggestions? Cheers Lorenzo ######################################################### library(plotrix) set.seed(1234) myseq <- abs(rnorm(25)) myseq[20] <- 100 #introduce outlier! A <- matrix(myseq, ncol=5,nrow=5) pdf("test_color_scale_log-fixed.pdf") oldpar<-par( mar = c(4.5,5, 2, 1) + 0.1, cex.axis=1.4,cex.lab=1.6,cex.main=1.6) color2D.matplot(log(A),main="Title",c(0.2,1),c(0.2,0.5),c(0,0), xlab = "", ylab="", show.legend=TRUE, show.values=0,vcol="black",vcex=1, axes=FALSE) ## axis(1,at=c(0.5,1.5,2.5,3.5,4.5),labels=prefix_vec_short) ## axis(2,at=rev(c(0.5,1.5,2.5,3.5,4.5)),labels=prefix_vec_short) for(i in 1:5) { for(j in 1:5) { text(i-0.5,j-0.5,formatC(A[6-j,i],format="f",digits=1),col="white") } } box() par(oldpar) dev.off()> Lorenzo, > > This is a bit ugly but should work. Instead of using plotrix's > show.values, > use the text() command: > > > for(i in 1:5) { > for(j in 1:5) { > text(i-0.5,j-0.5,format(A[6-j,i],digits=3),col="white") > } > } > > -- > View this message in context: > http://r.789695.n4.nabble.com/Plotrix-Trick-tp2265893p2266390.html > Sent from the R help mailing list archive at Nabble.com. >

Lorenzo, I think your question was already answered by Jan van der Laan - http://r.789695.n4.nabble.com/Plotrix-Trick-tp2265893p2266722.html -- View this message in context: http://r.789695.n4.nabble.com/Plotrix-Trick-tp2267177p2267225.html Sent from the R help mailing list archive at Nabble.com.