0

我有一个具有 1 或 0 值的数据框,并绘制了一个热图和一个树状图。

链接:https ://drive.google.com/file/d/1lHJ8UNRGG8tfxux6kT_QSPSe_elduZ9g/view?usp=sharing

用于绘制树状图的 R 脚本是

library(pheatmap)
library(tidyverse)
library(ComplexHeatmap)

myData <- read.csv('inputfile.csv', header = T)
#myData2 <- myData[,-1]
#rownames(myData2) <- myData[,1] ##change first row into rowname!!! 

myData %>% dim()
myData %>% unique() %>% dim()

myData <- unique(myData) #remove same mutations
colnames(myData)
rownames(myData)

m_myData <- myData %>% as.data.frame() %>% rownames_to_column('index') %>% select(-index) %>% 
column_to_rownames('X') #change columnanmes


myData$X %>% length() 
myData$X %>% unique() %>% length()


Heatmap(m_myData, clustering_method_columns = "average", column_dend_height = unit(100, "mm"))
# I think this part is the most important

输出是

在此处输入图像描述 我认为这种聚类是错误的,因为它有空格,尽管可以通过再次仅对列进行排序来填充空间。

它必须是这样的

在此处输入图像描述

(我用 Illustrator 手动排序了列顺序)

我该怎么做才能对列进行聚类?

4

0 回答 0