简体   繁体   中英

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

在此处输入图片说明

弄清楚我需要重新采样数据框以创建树状图。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM