简体   繁体   English

如何在R的热图中添加水平分隔符

[英]How to add horizontal separator in R's heatmap.2

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: 假设我有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")

You can use the parameter rowsep in heatmap.2 function (similarly, if you're interested in adding vertical lines, you can use parameter colsep ). 您可以在heatmap.2函数中使用参数rowsep (类似地,如果您对添加垂直线感兴趣,可以使用参数colsep )。

Here, you want to put a separation after the 8th values and then after the 23rd so you can do: 在这里,你想在第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: to retrieve the places of the horizontal lines based on the block vectors, you can do 注意:要根据block矢量检索水平线的位置,您可以这样做

which(row.names(mtcars)==block1[length(block1)]) # 8
which(row.names(mtcars)==block2[length(block2)]) # 23

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM