1

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

使用的代码在这里:

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
4

1 回答 1

0

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

您可能还希望将 传递row_side_colors为 adata.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")])

在此处输入图像描述

于 2018-05-05T15:02:27.450 回答