使用 pheatmap 的聚类注释

Cluster annotations using pheatmap

因此,我正在尝试使用 R 中的 pheatmap 函数创建一个漂亮的热图。

我想要在树状图停止和图表开始的地方添加彩色条,以便注释不同的集群。就像穿过列的水平粗线 运行 一样,当它传递到另一个集群时会改变颜色。我认为这很常见。但是我无法弄清楚 pheatmap 中的 'annotations' 。有什么想法吗?

    structure<-matrix(rnorm(10000),ncol=100,nrow=100)
    dist_structue<-dist(structure)
    clustering<-hclust(dist)   
    cols2 = colorRampPalette(c('green','white','red'))(20) 
    annotation <- data.frame(Var1 = factor(cutree(clustering, k = 4))    
    heat_chem <- pheatmap(as.matrix(dist_structure),
                 clustering_distance_rows=dist_structure, 
                 cellwidth = 4, cellheight = 4, cluster_rows=T,cluster_cols=T, legend = T,
                 clustering_distance_cols = dist_structure, show_rownames = TRUE,
                 fontsize_row = 5, annotation_row = annotation,
                 show_colnames = FALSE, cutree_cols = 4, cutree_rows=4, 
                 color = cols2,
                 main = 'Heatmap')

annotation 的行名与 as.matrix(dist_structure)

的行名不匹配