jokergoo / ComplexHeatmap

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

About the legend alignment #964

Open omrctnr opened 2 years ago

omrctnr commented 2 years ago

These days, I have been using the ComplexHeatmap to visualize my training data. While making plots, I stuck at the aligment of legends attached below.

rplot_default

For explaining easily, I converted my question into an image.  

rplot_desired

Normally, when I had the size of labels and title of the annotation legends minimized. It became the way I wanted. But, after the rendering, they seem very small when compared to the Heatmap_legends. 

To sum up, How can I sort the AntibioticsGroup and _po_eczemauk1yr legends one under the other ?

Here's my code: Thank you in advance.


p1<- Heatmap(csec_f5_mat,
        cluster_rows = FALSE,
        col = colorRamp2(c(0,1,2,3,4), c("#b9b8b9", "#4151FF","#33FF00", "#FFFF33", "#E61A33")),
        show_column_names = FALSE,
        #name = "GeneCount", 
        #col = col_fun,
        #gaps_row = c(6,9,15,18,19,20,26,28,29,30,38,39,43),
        column_title = "C-section filtered more than 5 gene ",
        column_title_side = c("top"),
        row_names_side = c("left"),
        split = csec_5f_rowann["AntibioticGroup"],
        row_title = "ARGs",
        row_title_gp = gpar( fontsize = 16, fontface= "bold"),
        row_names_gp = gpar(fontsize = 15),
        column_title_gp = gpar(fontsize = 15, fontface = "bold"),
        top_annotation = HeatmapAnnotation(po_eczemaUK_1yr = as.matrix(dplyr::select((dplyr::filter(misbair_metadata, ba_delivery_bi=="C-section")),po_eczemaUK_1yr)),
                                           col= list(po_eczemaUK_1yr= eczemacol),
                                           simple_anno_size = unit(5, "mm"),
                                           annotation_name_gp = gpar(fontsize = 13),
                                           #annotation_name_side = "left",
                                           show_annotation_name=FALSE,
                                           show_legend = TRUE,
                                           annotation_legend_param = list(
                                             po_eczemaUK_1yr = list(
                                               title_position= "topleft",
                                               title_gp = gpar(fontsize = 16, 
                                                               fontface = "bold"), 
                                               labels_gp = gpar(fontsize = 15)))),
        left_annotation = rowAnnotation(AntibioticGroup= as.matrix(csec_5f_rowann["AntibioticGroup"]),
                                         col= list(AntibioticGroup= antbiocol),
                                         simple_anno_size = unit(5, "mm"),
                                        show_annotation_name=FALSE,
                                        show_legend = TRUE,
                                        annotation_legend_param = list(
                                          AntibioticGroup = list(
                                            title_position= "topleft",
                                            title_gp = gpar(fontsize = 16, 
                                                            fontface = "bold"), 
                                            labels_gp = gpar(fontsize = 15)))),
        heatmap_legend_param = list(title = "GeneCount",
                                    title_gp = gpar(col = "black", fontsize = 16, fontface="bold"),
                                    #labels = 0:4,
                                    legend_height = unit(20, "cm"),
                                    legend_width  = unit(20,"cm"),
                                    title_position = "lefttop",
                                    direction = "horizontal",
                                    labels_gp = gpar(fontsize= 15, fontface = "bold"))
        )

draw(p1,heatmap_legend_side ="bottom", annotation_legend_side="right",
     legend_grouping = "original")
jokergoo commented 2 years ago

The second plot should be the right behavior. Can you also send me the data objects you used in the code?