jokergoo / ComplexHeatmap

Make Complex Heatmaps
https://jokergoo.github.io/ComplexHeatmap-reference/book/
Other
1.29k stars 225 forks source link

Get nicer plot with anno_mark #1033

Open france-hub opened 1 year ago

france-hub commented 1 year ago

Hello!

Thanks for ComplexHeatmap!! I was wondering what's the best way to get something like B here (Alvisi G,et al. Multimodal single-cell profiling of intrahepatic cholangiocarcinoma defines hyperactivated Tregs as a potential therapeutic target. J Hepatol. 2022 Nov;77(5):1359-1372.): image

I have a gene co-expression heatmap and I want to show selected genes in the areas of high correlation. Here is my attempt with anno_mark:

position <- which(rownames(mat)%in%genes)

row_an <- rowAnnotation(Genes = anno_mark(at = position,
                                           labels = rownames(mat)[position],
                                           labels_gp = gpar(fontsize = 6),
                                           link_width = unit(5, "mm"),
                                           padding = unit(1, "mm"),
                                           link_gp = gpar(lwd = 1),
                                          extend = unit(1, "mm")))

ht.3 <- Heatmap(mat, name = "Spearman correlation",
                column_names_gp = grid::gpar(fontsize = 0),
                row_names_gp = grid::gpar(fontsize = 0),
                right_annotation = row_an,
                heatmap_legend_param = list(legend_direction = "horizontal")) 
draw(ht.3, heatmap_legend_side = "bottom")

where genes are the selected genes I want to plot.

This is what I get: heat_corr

The heatmap is a bit confusing. I tried to use anno_zoom or anno_textbox but would like to maintain the rows clustering and I would prefer not to split the rows.

Is it doable?

Thanks, Francesco

jokergoo commented 1 year ago

Do not set padding = unit(1, "mm"). It makes labels too far from each other.

And like figure B, I think you can also set different colors to the labels and segments (by label_gp and link_gp)?