You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在指定行位置水平切割pheatmap绘制的热图?

在pheatmap中指定行位置实现水平切割

我使用以下R代码绘制了热图,希望在指定行位置完成水平切割(无需通过聚类方式,效果为热图中出现水平分割线):

test <- data.frame(revenue=c(34, 10, 0.40, 49, 43, 55, 99),
                   expenses=c(22, 0.26, 31, 40, 20, 25, 22),
                   profit=c(12, 10, 0.14, 0.9, 0.8, 15, 16))

rownames(test) <- c("Gene1",
                    "Gene2",
                    "Gene3",
                    "Gene4",
                    "Gene5",
                    "Gene6",
                    "Gene7")    
test
col_palette <- colorRampPalette(colors = c("green", "white", "red"))(30)
pheatmap(test, 
         cutree_rows = 1, 
         color = col_palette,
         scale = "none",
         cluster_cols = F,
         cluster_rows=F)

解决方案:使用gaps_row参数指定分割位置

pheatmap包自带的gaps_row参数可以直接实现指定行位置的水平切割,无需依赖聚类。只需在绘图函数中添加该参数,传入需要分割的行索引(表示在该行之后插入分割线)即可:

pheatmap(test, 
         color = col_palette,
         scale = "none",
         cluster_cols = F,
         cluster_rows=F,
         gaps_row = c(3) # 在第3行(Gene3)之后添加水平分割线
)
  • 如果需要多段分割,比如在第2行和第5行之后都添加分割线,只需传入向量c(2,5)即可。
  • 该参数完全不需要聚类支持,精准对应你指定的行位置,实现目标效果。

内容的提问来源于stack exchange,提问作者Lara

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 23:45:40