我使用ComplexHeatmap来显示基因在几个细胞中的表达。下面是一个玩具例子,每行代表一个基因。
library(ComplexHeatmap)
library(circlize)
set.seed(123)
nr1 = 4; nr2 = 14; nr3 = 16; nr = nr1 + nr2 + nr3
nc1 = 2; nc2 = 2; nc3 = 2; nc = nc1 + nc2 + nc3
mat = cbind(rbind(matrix(rnorm(nr1*nc1, mean = 1, sd = 0.5), nr = nr1),
matrix(rnorm(nr2*nc1, mean = 0, sd = 0.5), nr = nr2),
matrix(rnorm(nr3*nc1, mean = 0, sd = 0.5), nr = nr3)),
rbind(matrix(rnorm(nr1*nc2, mean = 0, sd = 0.5), nr = nr1),
matrix(rnorm(nr2*nc2, mean = 1, sd = 0.5), nr = nr2),
matrix(rnorm(nr3*nc2, mean = 0, sd = 0.5), nr = nr3)),
rbind(matrix(rnorm(nr1*nc3, mean = 0.5, sd = 0.5), nr = nr1),
matrix(rnorm(nr2*nc3, mean = 0.5, sd = 0.5), nr = nr2),
matrix(rnorm(nr3*nc3, mean = 1, sd = 0.5), nr = nr3))
)
mat = mat[sample(nr, nr), sample(nc, nc)] # random shuffle rows and columns
colnames(mat) = paste0("col", seq_len(nc))
rownames(mat) = c("MS4A1","BANK1" ,"CD79A","IL7R", "CD40LG","CD8A", "CD8B", "PECAM1","TM4SF1","STC1",
"LUM","COL1A1","COL1A2","KRT18" ,"KRT19","EPCAM","TPSAB1","KIT","C1QB", "LYZ","AIF1",
"GNLY", "KLRD1","CSF3R","FCGR3B","MZB1","IGLL5","SSR4", "RRM2", "HMGN2","CTLA4","FOXP3","TCL1A","IRF7")
col_fun = colorRamp2(c(-2, 0, 2), c("green", "white", "red"))
ht_opt(heatmap_column_names_gp = gpar(fontfamily = "Arial"),
heatmap_row_names_gp = gpar(fontfamily = "Arial",fontface = "italic",fontsize = 11),
heatmap_column_title_gp = gpar(fontfamily = "Arial"),
heatmap_row_title_gp = gpar(fontfamily = "Arial"),
legend_title_gp = gpar(fontfamily = "Arial"),
legend_labels_gp = gpar(fontfamily = "Arial"))
ht = Heatmap(mat,
# Remove name from fill legend
name = "Expression",
# Keep original row/col order
row_order = rownames(mat), column_order = colnames(mat),
rect_gp = gpar(col = "#7d7b7d", lwd = 1),
column_gap = unit(1.5, "mm"),
row_gap = unit(1.5, "mm"),
col = col_fun,
heatmap_legend_param = list(color_bar = "continuous", legend_direction = "horizontal",
at = c( -1, 0, 1, 2, 3),legend_width = unit(5, "cm"),
title_position = "lefttop"),
show_row_names = TRUE, show_column_names = TRUE,
show_row_dend = FALSE, show_column_dend = FALSE,
row_title = NULL)
draw(ht, heatmap_legend_side = "bottom")
正如你所看到的,有些行名(基因名)没有完全显示,例如,FCGR3B(行25),PECAM1(行8)。我该如何解决这个问题?
1条答案
按热度按时间esbemjvw1#
可以在
draw
函数中使用padding
参数就你来说10毫米就很好了
更多细节见这里Jokergoo CHM图书