如何在 heatmaply 热图中增加一列

How to have an additional coloumn in a heatmaply heatmap

我正在使用 heatmaply 获取多个评分者对使用相同 Leikert 量表(ECOG 表现状态)评分的一系列问题的反应的聚类热图。热图效果很好(尽管像这样对有序数据使用层次聚类可能不是最好的)。我想在热图中显示一个额外的列,它有一个额外变量的颜色编码信息,例如年龄。 附上我使用该包生成的示例热图。蓝色栏包含有关患者性别的信息,但没有颜色编码。我想知道是否可以这样做。也欢迎任何关于用于序数数据的正确聚类方法的输入。
Original heatmap link

使用的代码在这里:

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

该代码确实为这两个因素生成了颜色编码的注释。然而,当有足够多的关卡时,配色方案默认为彩虹方案,这会很难区分。您可能需要尝试对热图进行子集化,或者尝试在 heatmaply.

中设置不同的 row_side_palette

您可能还想将 row_side_colors 作为 data.frame 而不是向量传递,以确保它们在行名和悬停文本中的命名正确。

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

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")])