Dear R-helper: Suppose we have a matrix: Gene sample1 sample2 Gcnt1 12.0000 52.80000 Max 8.8000 39.10000 Tmem176b 67.9000 304.70000 Shmt2 8.6000 42.40000 Rtn4 11.5000 57.70000 Il17re 7.6000 38.80000 Bclp2 6.2000 32.10000 Mobkl3 4.4000 32.20000 Akr1b10 3.4000 30.10000 Atp6ap2 5.4000 48.20000 Snx2 5.7000 63.10000 Tmem176a 7.6000 91.40000 Klhl9 1.7000 30.30000 Fbxo27 1.0000 28.90000 Scd1 34.6000 0.70000 Tspan9 35.8000 4.20000 2210016L21Rik 39.1000 4.90000 Ctnnb1 212.1000 33.10000 Apoe 397.2000 74.20000 H2-DMb1 72.3000 14.10000 Ryk 31.7000 6.40000 Dapk2 85.4000 17.30000 Gzmm 179.4000 36.80000 Actb 12993.4000 2678.10000 Faim3 758.0000 157.60000 Aktip 209.4000 46.00000 Tbrg1 93.3000 21.30000 When I try to make heatmap based on this gene expression value table, I found that, when I set 'scale' to 'column', the heatmap will be always be red. I think this is because, there's very large values in the matrix (gene Actb), while the most are just very small. Thus, the color will be very ugly. I just wonder, how to set the color to make the heatmap look better? I have tried log-tranformation on the matrix and it's better now. But I do want to know if you have better ways to set the color span manually and make the heatmap look better without any log-transformation? Thanks in advance! Best, Hua
Before plotting a heatmap we usually standardize all genes to mean zero and variance 1. That way the green/red represent under/over expression with respect to the mean expression, which is roughly what the original 2-color arrays (that literally produced such heatmaps) were measuring. Of course, standardization assumes you have more than 2 samples. If your expression matrix is stored in the variable expr, with columns corresponding to samples and rows to genes, you can obtain a standardized expression matrix as stdExpr = t(scale(t(expr))) Peter On Tue, Nov 2, 2010 at 8:50 AM, Hua <kaixinsjtu at gmail.com> wrote:> Dear R-helper: > > Suppose we have a matrix: > > Gene ? ? ? ? ? ?sample1 sample2 > > Gcnt1 ? ? ? ? ? ?12.0000 ? ?52.80000 > Max ? ? ? ? ? ? ? 8.8000 ? ?39.10000 > Tmem176b ? ? ? ? 67.9000 ? 304.70000 > Shmt2 ? ? ? ? ? ? 8.6000 ? ?42.40000 > Rtn4 ? ? ? ? ? ? 11.5000 ? ?57.70000 > Il17re ? ? ? ? ? ?7.6000 ? ?38.80000 > Bclp2 ? ? ? ? ? ? 6.2000 ? ?32.10000 > Mobkl3 ? ? ? ? ? ?4.4000 ? ?32.20000 > Akr1b10 ? ? ? ? ? 3.4000 ? ?30.10000 > Atp6ap2 ? ? ? ? ? 5.4000 ? ?48.20000 > Snx2 ? ? ? ? ? ? ?5.7000 ? ?63.10000 > Tmem176a ? ? ? ? ?7.6000 ? ?91.40000 > Klhl9 ? ? ? ? ? ? 1.7000 ? ?30.30000 > Fbxo27 ? ? ? ? ? ?1.0000 ? ?28.90000 > Scd1 ? ? ? ? ? ? 34.6000 ? ? 0.70000 > Tspan9 ? ? ? ? ? 35.8000 ? ? 4.20000 > 2210016L21Rik ? ?39.1000 ? ? 4.90000 > Ctnnb1 ? ? ? ? ?212.1000 ? ?33.10000 > Apoe ? ? ? ? ? ?397.2000 ? ?74.20000 > H2-DMb1 ? ? ? ? ?72.3000 ? ?14.10000 > Ryk ? ? ? ? ? ? ?31.7000 ? ? 6.40000 > Dapk2 ? ? ? ? ? ?85.4000 ? ?17.30000 > Gzmm ? ? ? ? ? ?179.4000 ? ?36.80000 > Actb ? ? ? ? ?12993.4000 ?2678.10000 > Faim3 ? ? ? ? ? 758.0000 ? 157.60000 > Aktip ? ? ? ? ? 209.4000 ? ?46.00000 > Tbrg1 ? ? ? ? ? ?93.3000 ? ?21.30000 > > When I try to make heatmap based on this gene expression value table, I found that, when I set 'scale' to 'column', the heatmap will be always be red. I think this is because, there's very large values in the matrix (gene Actb), while the most are just very small. Thus, the color will be very ugly. I just wonder, how to set the color to make the heatmap look better? ?I have tried log-tranformation on the matrix and it's better now. But I do want to know if you have better ways to set the color span manually and make the heatmap look better without any log-transformation? > > Thanks in advance! > > Best, Hua > ______________________________________________ > R-help at r-project.org mailing list > 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. >
On 11/03/2010 02:50 AM, Hua wrote:> ... > When I try to make heatmap based on this gene expression value table, I found that, when I set 'scale' to 'column', the heatmap will be always be red. I think this is because, there's very large values in the matrix (gene Actb), while the most are just very small. Thus, the color will be very ugly. I just wonder, how to set the color to make the heatmap look better? I have tried log-tranformation on the matrix and it's better now. But I do want to know if you have better ways to set the color span manually and make the heatmap look better without any log-transformation? >Hi Hua, It is not all that easy, but can be done. I read in your data as "genexp". Notice how I split up the data into three ranges, adding the range extremes in color.scale (plotrix) and then removing the extremes. expcol[genexp$sample2<100]<- color.scale(c(0,100,genexp$sample2[genexp$sample2<100]), c(1,0.5),c(0,0.5),0)[-(1:2)] expcol[genexp$sample2>=100&genexp$sample2<1000]<- color.scale(c(100,1000,genexp$sample2[genexp$sample2>=100&genexp$sample2<1000]), c(0.5,0.1),c(0.5,0.9),0)[-(1:2)] expcol[genexp$sample2>1000]<- color.scale(c(1000,10000,genexp$sample2[genexp$sample2>=1000]), c(0.1,0),c(0.9,1),0)[-(1:2)] barplot(rep(1,27),col=expcol) color.legend(0,-0.1,15,-0.05,c(0,100,1000,10000), rect.col=c("red","#808000","#1ae600","green")) Jim
Reasonably Related Threads
- Loop Function to Create Multiple Scatterplots
- Any method to speed up this problem?
- Error en nlm(logdgenexpn, p = c(vmomest[[1]], vmomest[[2]]), x = x.genexp, : valor no finito provisto por 'nlm'
- Writing Vector to a File
- [LLVMdev] Problem While Running Test Suite