Keru Chen
Keru Chen

Reputation: 457

R - How to turn off reorder function in heatmap.2 when plot dendrogram

I was trying to use heatmap.2 to plot a double dendrogram with a heatmap. I have two pre-made dendrograms, which i fed them into Rowv = dend_row and Colv = dend_col. The issue is the dendrogram is also reordered. I learnt from the package that in heatmap.2, if a dendrogram is fed in Rowv / Colv, then it is used "as-is", ie without any reordering. So I make sure that the objects fed into the Rowv / Colv are already dendrograms (by using as.dendrogram), the dendrogram still reordered.

env.hc2 <- env %>% dist(method = 'euclidean') %>% 
hclust(method = 'ward.D') %>% as.dendrogram %>% ladderize %>% 
 color_branches(k=4)

female.hc2 <- female %>% as.dist(female) %>% hclust(method = 'com') %>%
 as.dendrogram %>% ladderize %>% 
 color_branches(k=4)

heatmap.2(female_env_matrix,  
      main = paste("test"),  
      trace="none",          
      margins =c(5, 6),      
      col= my_palette,        
      breaks=col_breaks,     
      dendrogram ='both',      
      Rowv = female.hc2,  
      Colv = env.hc2,
      key.xlab = "GY",
      cexRow = 0.6,
      cexCol = 0.8,
      na.rm = TRUE
) 

Desire output:

enter image description here

enter image description here

Upvotes: 1

Views: 231

Answers (1)

Keru Chen
Keru Chen

Reputation: 457

Figured out that I need to resample the dataframe to create dendrogram.

Upvotes: 0

Related Questions