使用R中的'heatmap()'函数生成热图后,有没有办法聚焦并提取特定群集的成员?
我有一个4500 x 420成员的热图,它会很有用。
感谢。
答案 0 :(得分:2)
指定keep.dendro = TRUE
,您应该在Rowv
和Colv
的列表元素下提供数据。
这是?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
修改的
如果你想要小组成员,你需要先砍树。
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