使用以下代码:
library(gplots)
heatmap.2(as.matrix(mtcars),density.info="none",trace="none",Colv=FALSE,Rowv=FALSE,dendrogram="none",margin=c(10,10))
我可以创建热图。但我想要做的是添加给定块的水平分隔符:
假设我有3个块定义为列表:
block1 <- c("Mazda RX4","Mazda RX4 Wag","Datsun 710","Hornet 4 Drive","Hornet Sportabout","Valiant","Duster 360","Merc 240D")
block2 <- c("Merc 230","Merc 280","Merc 280C","Merc 450SE","Merc 450SL","Merc 450SLC","Cadillac Fleetwood", "Lincoln Continental","Chrysler Imperial" ,"Fiat 128","Honda Civic","Toyota Corolla","Toyota Corona","Dodge Challenger","AMC Javelin")
block3 <- c("Camaro Z28","Pontiac Firebird","Fiat X1-9","Porsche 914-2","Lotus Europa","Ford Pantera L","Ferrari Dino","Maserati Bora","Volvo 142E")
答案 0 :(得分:16)
您可以在rowsep
函数中使用参数heatmap.2
(类似地,如果您对添加垂直线感兴趣,可以使用参数colsep
)。
在这里,您希望在第8个值之后放置分隔,然后在第23个之后放置分离,以便您可以执行以下操作:
heatmap.2(as.matrix(mtcars),
density.info="none",
trace="none",
Colv=FALSE,
Rowv=FALSE,
dendrogram="none",
margin=c(10,10),
# now the separations:
rowsep=c(8, 23))
NB:根据block
向量检索水平线的位置,你可以做到
which(row.names(mtcars)==block1[length(block1)]) # 8
which(row.names(mtcars)==block2[length(block2)]) # 23