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

如何使用ComplexHeatmap调整热图单元格尺寸?

调整ComplexHeatmap热图单元格尺寸的方法

嘿,要调整ComplexHeatmap绘制的热图单元格尺寸其实很简单,直接在Heatmap()函数里加几个参数就行,我给你说几个常用的方法:

1. 统一设置所有行/列的单元格尺寸

如果想让所有单元格的高度或宽度保持一致,可以用row_height和column_width参数,配合unit()函数指定具体的长度单位(比如mm、cm、char等)。

比如你可以把代码改成这样:

Heatmap(gsea.heatmap.df, 
        cluster_rows = FALSE, 
        cluster_columns = FALSE, 
        show_row_dend = FALSE, 
        show_column_dend = FALSE, 
        col = colorRamp2(c(-1, 0, 1), c("red", "white", "blue")), 
        heatmap_legend_param = list(color_bar = "continuous", 
                                    at = c(0, -0.1, -0.2, -0.3, -0.4, -0.5, -0.6, -0.7, -0.8, -0.9, -1), 
                                    labels = c("1", "0.9", "0.8", "0.7", "0.6", "0.5", "0.4", "0.3", "0.2", "0.1", "0")),
        # 新增调整单元格尺寸的参数
        row_height = unit(12, "mm"),  # 所有行的高度设为12毫米
        column_width = unit(10, "mm") # 所有列的宽度设为10毫米
)

2. 单独设置特定行/列的尺寸

如果需要某几行或列的尺寸和其他不一样,可以给row_height或column_width传入一个向量,对应每一行/列的尺寸。比如:

# 第一行高度设为15mm,其余行设为10mm
row_height = unit(c(15, rep(10, nrow(gsea.heatmap.df)-1)), "mm")
# 前两列宽度设为12mm,其余列设为8mm
column_width = unit(c(12,12, rep(8, ncol(gsea.heatmap.df)-2)), "mm")

3. 自适应内容调整

如果你的行名/列名太长导致显示不全,可以用row_names_max_width或column_names_max_height参数让热图自动适配内容,同时单元格尺寸也会跟着调整:

Heatmap(gsea.heatmap.df, 
        # 其他参数保持不变
        row_names_max_width = unit(5, "cm"), # 行名最大宽度设为5厘米,自动适配行宽
        column_names_max_height = unit(3, "cm") # 列名最大高度设为3厘米,自动适配列高
)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.20 10:27:13