Reputation: 7790
With the following codes:
library(gplots)
heatmap.2(as.matrix(mtcars),density.info="none",trace="none",Colv=FALSE,Rowv=FALSE,dendrogram="none",margin=c(10,10))
I can create the heatmap. But what I want to do is to add the horizontal separators of the given blocks:
Let say I have 3 blocks defined as lists:
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")
Upvotes: 9
Views: 7329
Reputation: 24074
You can use the parameter rowsep
in heatmap.2
function (similarly, if you're interested in adding vertical lines, you can use parameter colsep
).
Here, you want to put a separation after the 8th values and then after the 23rd so you can do:
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: to retrieve the places of the horizontal lines based on the block
vectors, you can do
which(row.names(mtcars)==block1[length(block1)]) # 8
which(row.names(mtcars)==block2[length(block2)]) # 23
Upvotes: 16