Entering edit mode
2.9 years ago
askif4
▴
20
I have a dataframe with 1 or 0 values and drew a heatmap and a dendrogram.
link: https://drive.google.com/file/d/1lHJ8UNRGG8tfxux6kT_QSPSe_elduZ9g/view?usp=sharing
R script for drawing dendrogram is
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
The output is
I think this clustering is wrong because it has empty spaces, although the space can be filled by sorting only columns again.
It has to be like this
(I have manually sorted column orders with Illustrator)
What do I have to do to cluster columns right?
*I have uploaded the same question in StackOverflow, but no one answered... so I ask this again.
What do you mean by empty spaces?
Empty space means, these two gaps can be rearranged (attached) without losing the integrity of the heatmap.
Two images seem to be a good challenge for spotting 12 differences between them. what is the criteria for reordering columns? None of the rows or column has 0s in all of them. Column (sample) names do not affect the heatmap.
You have to define what you want from the clustering. What is your definition of "right"? It is mathematical? If you want the columns to be in a particular order, calculate the score you're looking for, and then put them in that order. There's nothing erroneous about the clustering in your heat map. The "empty spaces" you refer to simply reflect undesired arrangement of the columns. You might check out Complex Heatmap: Changing order of clusters which can be applied to columns as well as rows. (See the manual: order of slices)