1

I have produced a heatmap using heatmap in base R, but would like to change the order of the rows appearing in the dendogram. I would like to know how I can alter my code to achieve this. I have tried using the function reorder.dendogram however this doesn't work with my dataframe.

This is the data I'm working with and the code I have used so far

dd <- structure(list(A = c(26, 64, 54, 98, 95), 
                     B = c(63, 64, 26, 82, 3), 
                     C = c(11, 17, 53, 83, 35), 
                     D = c(15, 13, 72, 71, 17), 
                     E = c(94, 19,51, 19, 55),
                     F = c(89, 47, 49, 15, 68)),
                .Names = c("A", "B", "C", "D", "E", "F"), 
                 row.names = c(NA, 5L), class = "data.frame")

 #    A  B  C  D  E  F
 # 1 26 63 11 15 94 89
 # 2 64 64 17 13 19 47
 # 3 54 26 53 72 51 49
 # 4 98 82 83 71 19 15
 # 5 95 35 35 17 55 68

heatmap(t(dd),
        scale = 'none',
        col = brewer.pal(6, 'RdPu'),
        xlab = 'Cluster',
        main = "Heatmap")

My desired output would be the clusters along X axis being ordered 1 to 5 rather than the current order. How can I alter my code to achieve this?

M--
  • 25,431
  • 8
  • 61
  • 93
Laney-G
  • 11
  • 1
  • 1
    Possible duplicate : [Order of rows in heatmap?](https://stackoverflow.com/questions/5320814/order-of-rows-in-heatmap) – maydin Aug 21 '19 at 18:28
  • 1
    How about `heatmap(t(dd), scale = 'none', col = brewer.pal(6, 'RdPu'), xlab = 'Cluster', main = "Heatmap", Colv=NA)` ? – G5W Aug 21 '19 at 19:34
  • Make the dendrogram first, rotate using dendextend (https://cran.r-project.org/web/packages/dendextend/vignettes/introduction.html#changing-a-dendrograms-structure), and supply it to the Rowv parameter in heatmap. – Tal Galili Aug 22 '19 at 11:54

0 Answers0