如何增加 ComplexHeatmap 中的单元格高度?

How to increase cell height in ComplexHeatmap?

我使用下面的代码使用 Heatmap ()库("ComplexHeatmap"))为我的 DEG 基因创建热图。

我的问题是细胞高度非常小并且行名称(88个基因ID)不能清楚地观察到。

我增加了行名字体和行尾大小,但它对我不起作用。

注意:我无法使用 "cell_fun" 功能!

~先谢谢大家了

这是我的代码:

library(gplots)
library("ComplexHeatmap")
library(dendextend)
library("RColorBrewer")
filename <- "male-female-88-TMMb.matrix"
my_data <- read.table(filename, sep='\t', quote='', stringsAsFactors=FALSE, header=TRUE)
row.names(my_data) <- my_data$samples
my_data <- my_data[, -1]
my_data <- my_data/rowSums(my_data)

row.scaled.expr <- as.matrix(my_data) 

row.names(my_data) <- my_data$samples
my_matrix <- as.matrix(my_data) 
my_data <- my_data[, -1]

data.prop <- my_data/rowSums(my_data)

mycol <- colorRampPalette(brewer.pal(10, "RdYlBu"))(256)

.hist = anno_histogram(row.scaled.expr, gp = gpar(fill = "olivedrab3"))

.density = anno_density(row.scaled.expr, type = "line", gp = gpar(col = "blue"))

ha_mix_top = HeatmapAnnotation(hist = .hist, density = .density)

.violin = anno_density(row.scaled.expr, type = "violin", 
                           gp = gpar(fill = "darkorchid4"), which = "row")

ha_mix_right = HeatmapAnnotation (violin = .violin,
                                  which = "row", width = unit(4.5, "cm"))

Heatmap (as.matrix(data.prop), km = 2, name = "TMM", col = mycol,
         column_names_gp = gpar(fontsize = 8.5),
         row_names_side = "left",
         row_dend_side = "left",
         clustering_method_columns = "ward.D",
         clustering_method_rows = "ward.D",
         column_dend_side = c("bottom"),
         column_dend_height = unit(6, "mm"),
         row_dend_width = unit(3.6, "cm"),
         row_dend_gp = gpar (15),
         gap = unit(1, "mm"),
         row_title_gp = gpar(col = c("red2", "blue4"), font = 2:2),
         row_names_gp = gpar(col = c("red2", "blue4"), fontsize = c(8.4, 8.6)),
         rect_gp = gpar(col = "gray12", lty = 1, lwd = 0.2),
         top_annotation = ha_mix_top, 
         top_annotation_height = unit(3, "cm")) + ha_mix_right

我的 "data.prop" 文件的标题:

head(data.prop)

                          F1         F2        F3         M1          M2
DN107669_c1_g2_i1 0.68965517 0.05627846 0.2540664 0.00000000 0.000000000
DN101742_c5_g1_i2 0.27241615 0.20739220 0.5140315 0.00000000 0.006160164
DN107731_c4_g1_i4 0.17056856 0.56187291 0.2675585 0.00000000 0.000000000
DN108762_c0_g1_i9 0.00000000 0.85127479 0.1487252 0.00000000 0.000000000
DN111305_c2_g4_i1 0.08341354 0.32996471 0.5731473 0.01347449 0.000000000
DN101817_c3_g1_i3 0.11783015 0.51504372 0.2967245 0.01081962 0.050096339
                           M3
DN107669_c1_g2_i1 0.000000000
DN101742_c5_g1_i2 0.000000000
DN107731_c4_g1_i4 0.000000000
DN108762_c0_g1_i9 0.000000000
DN111305_c2_g4_i1 0.000000000
DN101817_c3_g1_i3 0.009485697

这是我从 ComplexHeatmap (Heatmap()) 的创建者顾祖光那里得到的答案:

How do you save the image into a file? Using pdf() function or click "save" or "export" in Rstudio?

If you use pdf(), you can set the size of the plot by width and height argument.

If you directly save the image in Rstudio, there must be some place that you can adjust the size of the pdf file.

我在 Rstudio 中使用了他的指导,它解决了问题 ;-)

您可以只使用 heatmap_height 参数:

heatmap_width and heatmap_height control the width/height of the complete heatmap including all heatmap components (excluding the legends)

例如:

Heatmap(mat, ..., heatmap_height = unit(1, "cm")*nrow(mat))