【问题标题】:R gplots: Heatmap with side coloursR gplots:带有侧面颜色的热图
【发布时间】:2015-12-07 14:36:27
【问题描述】:

我想使用 gplots 包中的 heatmap.2 函数创建热图。这是一个最小的例子。

require(gplots)

# create symmetric matrix
x = matrix(rnorm(100), nrow=10)
diag(x)         <- 1
x[upper.tri(x)] <-  t(x)[upper.tri(x)]
colnames(x)     <- rownames(x) <- letters[1:nrow(x)]

# create side colours
varcols = setNames(rainbow(nrow(x)), rownames(x))

# create heatmap
heatmap.2(x,
          symm = TRUE,             
          trace = "none",          
          revC=TRUE, # <-- THIS IS THE PROBLEM
          ColSideColors = varcols,
          RowSideColors = varcols
          )  

问题是sidecolors。 x 是一个对称矩阵,因此列和行应该具有相同的侧色。只要revC = FALSE 就可以了。但是,当我使用 revC = TRUE 时,颜色的顺序就搞砸了。有时 - 在小例子中 - 它有助于反转 ColSideColors,但这并不总是有效。

我做错了什么还是这是gplots 错误?

【问题讨论】:

    标签: r heatmap gplots


    【解决方案1】:

    对于遇到此问题的其他人,这是我解决它的方法:

    thing = heatmap.2(my_matrix,...RowSideColors=row_cols, revC=F)
    ordinary_order = thing$rowInd
    reversal = cbind(ordinary_order, rev(ordinary_order))
    rev_col = row_cols[reversal[,2]]; rev_col = rev_col[order(reversal[,1])];
    
    heatmap.2(my_matrix, RowSideColors=rev_col, revC=T)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多