rcomplexheatmap

In the ComplexHeatmap, how to change the anno_barplot() title's angle?


I use the R package,complexheatmap to draw a heatmap. This is my code:

aa <- rowAnnotation("log10(FDR)" = anno_barplot(fdr), 
                    "log2(Fold Change)" = anno_barplot(fc, gp = gpar(fill = fc_color(fc))),
                    width = unit(3, 'cm'),
                    gap = unit(10, "points"))
Heatmap(matrix = mtx, 
             border = T, 
             column_order = ordered_sample, 
             heatmap_legend_param = list(title = "", 
             legend_height = unit(4, "cm")), column_names_rot = -90, 
             row_names_gp = gpar(fontsize = 8), 
             column_names_gp = gpar(fontsize = 8), 
             clustering_method_rows = "ward.D2", 
             name = "Scale(exp)", 
             cluster_column_slices = T, row_split = rr_,
             cluster_rows = T, 
             cluster_columns = F, 
             clustering_method_columns = "ward.D2",
             col = htmp_color, right_annotation = aa
        )

enter image description here

my question is how to turn log10(FDR) 90 degrees? This way the titles of the two Barplplots will not overlap


Solution

  • It's better if you can supply some sample data. Using an alternative example, annotation_name_rot = 90 seems to do the trick (rotating foo2 and bar2 bottom right):

    library(ComplexHeatmap)
    
    set.seed(123)
    mat = matrix(rnorm(100), 10)
    rownames(mat) = paste0("R", 1:10)
    colnames(mat) = paste0("C", 1:10)
    column_ha = HeatmapAnnotation(foo1 = runif(10), bar1 = anno_barplot(runif(10)))
    row_ha = rowAnnotation(foo2 = runif(10), bar2 = anno_barplot(runif(10)), annotation_name_rot = 90)
    Heatmap(mat, name = "mat", top_annotation = column_ha, right_annotation = row_ha)
    

    Created on 2024-04-25 with reprex v2.1.0