R:热图的行缩放不能正常工作
R: Row scaling not working correctly for heatmap
我目前正在为一些数据创建热图,其中每个项目 (OTU) 的值差异很大,因此我使用 scale="row"
选项。
我假设这将对每一行使用相同的颜色渐变,因此最大颜色(深绿色)和最小颜色(白色)始终存在。然而,正如您在下面看到的,一些从白色变为浅绿色,另一些变为深绿色或深绿色。
这是我一直在使用的代码:
library(gplots)
library(RColorBrewer)
data <-read.csv("Heatmap_data.csv", comment.char="#")
rnames <- data[,1] # assign labels in column 1 to "rnames"
mat_data <- data.matrix(data[,2:ncol(data)]) # transform column 2-5 into a matrix
rownames(mat_data) <- rnames # assign row names
my_palette <- colorRampPalette(c("white", "dark green"))(n = 1090)
heatmap(mat_data, Rowv=NA, Colv=NA, col = my_palette, scale="row", margins=c(23,15))
许多灰白色的值实际上是 0,如您在此处的数据中所见:
MB.11 MB.8 MB.7 MB.12 MB.9 MB.10 MB.4 MB.6 MB.5 MB.3 MB.2 MB.1 K2295 K229456 K2299 K2297 K2298 K2293 K2294 K2292 K2290 K2291
OTU_43 23.5019505852 4.3947267864 6 18.3651985319 3.0748596382 5.5431848853 71.853471596 24.1857966978 12.6422018349 13.2893694289 46.5896990741 21.0355475222 38.5817456801 7.723156853 55.9703296703 6.1243646222 72.4165876777 74.0147572816 46.6683375104 87.3876576884 23.2358576642 33.7528164347
OTU_48 27.7750325098 36.4134505159 9 55.0955955956 9.7370555209 8.8690958165 108.8913435528 25.8199721504 23.8256880734 10.3060415979 42.7864583333 4.7020635638 3.6397873283 3.2518555171 69.8124542125 0 3.1146919431 26.7984466019 124.2201336675 355.7125809751 38.2267335766 63.8762977689
OTU_162 8.0120286086 11.3007260222 2 8.7714381048 2.5623830318 3.3259109312 35.5563570784 19.6101054307 12.6422018349 16.0014856388 57.0486111111 31.9245368278 4.367744794 3.2518555171 6.3192307692 3.8973229414 12.4587677725 29.3506796117 11.6670843776 35.8513467439 47.2212591241 45.3666887564
OTU_64 16.0240572172 0 36 35.6339673006 0.5124766064 5.5431848853 3.7037871957 0 1.4587155963 0 24.7210648148 0 1.4559149313 0 0 0 0 0 0 3.3610637572 0 2.1776010603
OTU_60 0 61.5261750096 23 0 42.0230817218 0 0 0 8.752293578 7.5939253879 3.8032407407 11.6314203946 21.8387239699 13.8203859476 8.1247252747 0 22.5815165877 0 3.4314954052 14.0044323219 8.2449817518 3.6293351005
OTU_116 136.7386215865 8.7894535728 15 30.9741408075 23.0614472863 103.6575573549 0 0 0 0 0 0 31.3021710235 8.1296387927 28.586996337 28.9515418502 49.83507109 0 0 0 0 0
OTU_86 7.477893368 26.3683607184 1 2.1928595262 21.5240174672 16.6295546559 2.9630297565 0.653670181 0 0 13.3113425926 0 0 0 0.3009157509 0 0 0 0 2.8008864644 0.7495437956 1.0888005302
OTU_534 134.0679453836 0 15 0 26.6487835309 180.1535087719 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
OTU_75 81.7226918075 0 6 0 12.2994385527 121.3957489879 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
OTU_176 26.7067620286 0 0 19.461628295 26.6487835309 9.423414305 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7.9845372211
如有任何帮助,我们将不胜感激!
您分别缩放每一行的颜色。
heatmap(log(mat_data+1), Rowv=NA, Colv=NA, col = my_palette, scale="none", margins=c(23,15))
应该完成这项工作。
scale="none"
抑制任何缩放,log(mat_data+1)
将范围缩小到更合适的值。
我目前正在为一些数据创建热图,其中每个项目 (OTU) 的值差异很大,因此我使用 scale="row"
选项。
我假设这将对每一行使用相同的颜色渐变,因此最大颜色(深绿色)和最小颜色(白色)始终存在。然而,正如您在下面看到的,一些从白色变为浅绿色,另一些变为深绿色或深绿色。
这是我一直在使用的代码:
library(gplots)
library(RColorBrewer)
data <-read.csv("Heatmap_data.csv", comment.char="#")
rnames <- data[,1] # assign labels in column 1 to "rnames"
mat_data <- data.matrix(data[,2:ncol(data)]) # transform column 2-5 into a matrix
rownames(mat_data) <- rnames # assign row names
my_palette <- colorRampPalette(c("white", "dark green"))(n = 1090)
heatmap(mat_data, Rowv=NA, Colv=NA, col = my_palette, scale="row", margins=c(23,15))
许多灰白色的值实际上是 0,如您在此处的数据中所见:
MB.11 MB.8 MB.7 MB.12 MB.9 MB.10 MB.4 MB.6 MB.5 MB.3 MB.2 MB.1 K2295 K229456 K2299 K2297 K2298 K2293 K2294 K2292 K2290 K2291
OTU_43 23.5019505852 4.3947267864 6 18.3651985319 3.0748596382 5.5431848853 71.853471596 24.1857966978 12.6422018349 13.2893694289 46.5896990741 21.0355475222 38.5817456801 7.723156853 55.9703296703 6.1243646222 72.4165876777 74.0147572816 46.6683375104 87.3876576884 23.2358576642 33.7528164347
OTU_48 27.7750325098 36.4134505159 9 55.0955955956 9.7370555209 8.8690958165 108.8913435528 25.8199721504 23.8256880734 10.3060415979 42.7864583333 4.7020635638 3.6397873283 3.2518555171 69.8124542125 0 3.1146919431 26.7984466019 124.2201336675 355.7125809751 38.2267335766 63.8762977689
OTU_162 8.0120286086 11.3007260222 2 8.7714381048 2.5623830318 3.3259109312 35.5563570784 19.6101054307 12.6422018349 16.0014856388 57.0486111111 31.9245368278 4.367744794 3.2518555171 6.3192307692 3.8973229414 12.4587677725 29.3506796117 11.6670843776 35.8513467439 47.2212591241 45.3666887564
OTU_64 16.0240572172 0 36 35.6339673006 0.5124766064 5.5431848853 3.7037871957 0 1.4587155963 0 24.7210648148 0 1.4559149313 0 0 0 0 0 0 3.3610637572 0 2.1776010603
OTU_60 0 61.5261750096 23 0 42.0230817218 0 0 0 8.752293578 7.5939253879 3.8032407407 11.6314203946 21.8387239699 13.8203859476 8.1247252747 0 22.5815165877 0 3.4314954052 14.0044323219 8.2449817518 3.6293351005
OTU_116 136.7386215865 8.7894535728 15 30.9741408075 23.0614472863 103.6575573549 0 0 0 0 0 0 31.3021710235 8.1296387927 28.586996337 28.9515418502 49.83507109 0 0 0 0 0
OTU_86 7.477893368 26.3683607184 1 2.1928595262 21.5240174672 16.6295546559 2.9630297565 0.653670181 0 0 13.3113425926 0 0 0 0.3009157509 0 0 0 0 2.8008864644 0.7495437956 1.0888005302
OTU_534 134.0679453836 0 15 0 26.6487835309 180.1535087719 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
OTU_75 81.7226918075 0 6 0 12.2994385527 121.3957489879 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
OTU_176 26.7067620286 0 0 19.461628295 26.6487835309 9.423414305 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7.9845372211
如有任何帮助,我们将不胜感激!
您分别缩放每一行的颜色。
heatmap(log(mat_data+1), Rowv=NA, Colv=NA, col = my_palette, scale="none", margins=c(23,15))
应该完成这项工作。
scale="none"
抑制任何缩放,log(mat_data+1)
将范围缩小到更合适的值。