使用热图的自定义轴顺序。来自gplots的功能

时间:2018-02-16 16:01:52

标签: r heatmap gplots

我需要使用轴排列热图,如表中所示。

我的数据是csv格式:

"X" "Mescla" "HCL" "HSL" "Kmeans" "soma"
"1" "DR" 15.33559 14.7499 14.7556 14.32343 89.78054
"2" "DA" 16.59264 14.764 14.9968 14.36513 91.08672
"3" "UMR80" 16.28646 15.88403 14.01783 15.96327 94.55977
"4" "UMR" 16.46229 15.87505 14.34763 15.87903 94.83926
"5" "MR50" 16.61305 16.04243 14.85003 16.15599 96.20576

> data
      X   merge      A1      A2    K        sum
1    DR 15.33559 14.74990 14.75560 14.32343 89.78054
2    DA 16.59264 14.76400 14.99680 14.36513 91.08672
3 UMR80 16.28646 15.88403 14.01783 15.96327 94.55977
4   UMR 16.46229 15.87505 14.34763 15.87903 94.83926
5  MR50 16.61305 16.04243 14.85003 16.15599 96.20576

1 个答案:

答案 0 :(得分:0)

我的解决方案是使用参数Rowv = FALSE和Colv = FALSE:

library(gplots)
library(RColorBrewer)

rnames <- data[,1]
mat_data <- data.matrix(data[,3:ncol(data)-1])
rownames(mat_data) <- rnames
my_palette <- colorRampPalette(c("red", "yellow", "green"))(n = 299)
col_breaks = c(seq(-1,0,length=100), # for red
seq(0,0.8,length=100),  # for yellow
seq(0.81,1,length=100)) # for green

heatmap.2(mat_data,
  main = "Rank", # heat map title
  notecol="black",      # change font color of cell labels to black
  density.info="none",  # turns off density plot inside color legend
  trace="none",         # turns off trace lines inside the heat map                                                                               
  margins =c(7,5),     # widens margins around plot
  col=my_palette,       # use on color palette defined earlier
  Rowv=FALSE,
  Colv=FALSE,
  dendrogram="none")            # turn off column clustering

热图是:heatmap with axis ordered

相关问题