How to adjust the font size for axis labels in Complex Heatmap?

16.3k views Asked by At

I'm using ComplexHeatmap to create a heatmap in R. I have recreated a small heatmap here. I can't figure out from the documentation how to adjust the font size for the text on the x-axis.

a = matrix(1:9, nrow = 3, ncol = 3)
rownames(a) = c("alphabet","xylophone","tornado")
colnames(a) = c("c1","c2","c3")

my_heatmap = ComplexHeatmap::Heatmap(
        matrix = t(a),
        col = RColorBrewer::brewer.pal(9, "RdBu"))

This code produces this:

Heatmap

I want to adjust the font size for the c("alphabet","xylophone","tornado") text so that it is much smaller. How do I do this?

1

There are 1 answers

0
M-- On BEST ANSWER

You can use row_names_gp and column_names_gp to adjust y-axis and x-axis labels, respectively.

# if (!requireNamespace("BiocManager", quietly = TRUE))
#       install.packages("BiocManager")
# BiocManager::install("ComplexHeatmap")
#
# library(ComplexHeatmap)
# library(grid)
a = matrix(1:9, nrow = 3, ncol = 3)
rownames(a) = c("alphabet","xylophone","tornado")
colnames(a) = c("c1","c2","c3")

ComplexHeatmap::Heatmap(
  matrix = t(a),
  col = RColorBrewer::brewer.pal(9, "RdBu"),
  column_names_gp = grid::gpar(fontsize = 8),
  row_names_gp = grid::gpar(fontsize = 8))