Search code examples
rheatmapgplots

Changing line width of dendrogram in heatmap.2


I'm trying to plot a heatmap using gplots::heatmap.2() .There are a lot of rows and the dendrogram lines appear to be quite thin compared to the image. I 'm wondering if there is any technique to thicken the dendrogram lines as mentioned in this post for the pheatmap output. Thanks


Solution

  • Yes, the dendextend package does this easily. We can use its set() function here to achieve the desired effect.

    set.seed(123)
    dat <- matrix(rnorm(100), nrow = 10)
    
    library(gplots)
    library(dendextend)
    
    dd <- set(as.dendrogram(hclust(dist(dat))), "branches_lwd", 3)
    
    heatmap.2(dat, Rowv = dd, Colv = dd)
    

    enter image description here

    It's worth looking into all the other cool stuff Dendextend does.