如何在热图热图中添加额外的coloumn

时间:2018-03-16 16:15:30

标签: r heatmaply

我正在使用热图来获取来自多个评估者的回答的聚类热图,这些回答是使用相同的Leikert等级(ECOG Performance Status)评定的一系列问题。热图很好(尽管在序数数据上使用层次聚类,这可能不是最好的)。我想在热图中显示另一个coloumn,其中包含有关其他变量的颜色编码信息,例如年龄。 我附上了使用包生成的示例热图。蓝色的coloumn有关于患者性别的信息,但同样没有颜色编码。我想知道是否可以这样做。也欢迎任何有关用于序数数据的正确聚类方法的输入 Original heatmap link heatmap

使用的代码在这里:

library(heatmaply)
data4 <- structure(list(UID = c("D1", "D3", "D4", "D5", "D6", "D7", "D8", 
"D9", "D10", "D11", "D12", "D13", "D14", "D15", "D16"), R101 = c(2, 
1, 1, 1, 2, 1, 2, 1, 0, 2, 0, 1, 1, 1, 1), R102 = c(3, 2, 0, 
2, 3, 1, 2, 2, 0, 2, 3, 2, 2, 2, 2), R103 = c(2, 2, 2, 3, 3, 
0, 2, 3, 0, 1, 0, 4, 2, 2, 3), R104 = c(1, 0, 1, 1, 1, 1, 1, 
3, 0, 2, 1, 0, 0, 1, 2), R105 = c(1, 3, 2, 1, 1, 2, 1, 1, 0, 
3, 1, 0, 2, 1, 2), R106 = c(3, 4, 4, 4, 3, 3, 4, 4, 4, 4, 4, 
4, 3, 4, 4), R107 = c(1, 3, 3, 1, 2, 3, 2, 3, 3, 3, 3, 3, 1, 
3, 3), R108 = c(0, 4, 2, 2, 1, 3, 3, 2, 3, 3, 4, 3, 3, 3, 3), 
    R109 = c(0, 2, 0, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 1, 1), R110 = c(1, 
    1, 0, 1, 1, 1, 2, 1, 0, 1, 0, 1, 0, 1, 1), R111 = c(3, 2, 
    2, 3, 3, 2, 2, 3, 1, 3, 4, 2, 2, 3, 2), R112 = c(1, 2, 2, 
    1, 1, 1, 1, 3, 1, 2, 2, 2, 1, 1, 1), Gender = structure(c(2L, 
    1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("male", 
    "female"), class = "factor")), .Names = c("UID", "R101", 
"R102", "R103", "R104", "R105", "R106", "R107", "R108", "R109", 
"R110", "R111", "R112", "Gender"), row.names = c(NA, -15L), class = c("tbl_df", 
"tbl", "data.frame"))

p <-heatmaply(data4[1:13],fontsize_row = 8,fontsize_col = 6,Rowv =F,grid_gap = 0.5,colors = viridis(n = 256, alpha = 1, begin = 1,end = 0, option = "viridis"),branches_lwd = 0.2,row_side_colors =as.factor( data4$Gender))
p

1 个答案:

答案 0 :(得分:0)

代码确实为这两个因素生成了颜色编码的注释。但是,当有足够的级别时,颜色方案默认为彩虹方案,这很难区分。您可能需要尝试对热图进行子集化,或尝试在row_side_palette中设置不同的heatmaply

您可能还希望将row_side_colors作为data.frame而不是向量传递,以确保它们在rownames和hovertext中都能正确命名。

请参阅下面的代码,其中包括一些小调整。

heatmaply(
  data4[, setdiff(colnames(data4), c("Gender", "UID"))],
  plot_method = "plotly",
  fontsize_row = 8,
  fontsize_col = 6,
  Rowv = FALSE,
  grid_gap = 0.5,
  colors = viridis(n = 256, alpha = 1, begin = 1,end = 0, option = "viridis"),
  branches_lwd = 0.2,
  row_side_colors = data4[, c("Gender", "UID")])

enter image description here