0

I am making a heatmap and adding in an external dendrogram. I did as in the post at how to create a heatmap with a fixed external hierarchical cluster but the rows keeps gets reordered. The code is as follows:

    #TREE input
rep_tr <- read.tree(file= "tree.tre")


#first check 
is.ultrametric(rep_tr)
is.binary.tree(rep_tr)
is.rooted(rep_tr)
#fix and check if didnt pass
tree1 <- chronos(rep_tr)
is.ultrametric(tree1)


myTree.bifurcating<-multi2di(tree1)
is.binary.tree(myTree.bifurcating)



hc <- as.hclust.phylo(myTree.bifurcating)



tre <- as.phylo(hc)

dend <- as.dendrogram(hc)

plot(dend, horiz=TRUE)


#labels in dend but bottom to top. ANd order matrix 
h <- labels(dend)
hi <- matdata[h,]
b <- apply(hi, 2, rev)

pdf("class_tree.pdf")

heatmap.2(b, Rowv=dend, Colv=NA, dendrogram='row', col = colorpanel(9,"red","yellow","green"), density.info = "none", key=TRUE, keysize=1, margins = c(5,10), trace = "none", xlab = "Samples",  main = "Class", cexRow=0.7, cexCol=.5,  na.color="white")

dev.off()

The dendrogram gets added in. I put Rowv to the dendrogram but the rows are reordered.

Community
  • 1
  • 1
user3767953
  • 141
  • 1
  • 10

0 Answers0