Get names of specific members of clusters of heatmap() function R

1.4k views Asked by At

Once you generate a heat map using 'heatmap()' function in R, is there a way to focus in and extract the members of a specific cluster?

I have a heat map of 4500 x 420 members and it would be useful.

Thanks.

1

There are 1 answers

1
Roman Luštrik On

Specify keep.dendro = TRUE and you should have data available under the list elements of Rowv and Colv.

This is a slightly modified example from ?heatmap.

require(graphics); require(grDevices)
x  <- as.matrix(mtcars)
rc <- rainbow(nrow(x), start = 0, end = .3)
cc <- rainbow(ncol(x), start = 0, end = .3)
hv <- heatmap(x, col = cm.colors(256), scale = "column",
              RowSideColors = rc, ColSideColors = cc, margins = c(5,10),
              xlab = "specification variables", ylab =  "Car Models",
              main = "heatmap(<Mtcars data>, ..., scale = \"column\")",
              keep.dendro = TRUE)

hv$Rowv
'dendrogram' with 2 branches and 32 members total, at height 425.3447 

EDIT

If you want group members, you need to cut the tree first.

cutree(as.hclust(hv$Rowv), h = 200)

          Mazda RX4       Mazda RX4 Wag          Datsun 710      Hornet 4 Drive   Hornet Sportabout             Valiant 
                  1                   1                   1                   2                   3                   2 
         Duster 360           Merc 240D            Merc 230            Merc 280           Merc 280C          Merc 450SE 
                  3                   1                   1                   1                   1                   2 
         Merc 450SL         Merc 450SLC  Cadillac Fleetwood Lincoln Continental   Chrysler Imperial            Fiat 128 
                  2                   2                   3                   3                   3                   1 
        Honda Civic      Toyota Corolla       Toyota Corona    Dodge Challenger         AMC Javelin          Camaro Z28 
                  1                   1                   1                   2                   2                   3 
   Pontiac Firebird           Fiat X1-9       Porsche 914-2        Lotus Europa      Ford Pantera L        Ferrari Dino 
                  3                   1                   1                   1                   3                   1 
      Maserati Bora          Volvo 142E 
                  4                   1