This is a test version of Biostars. For the public version, visit https://www.biostars.org.
ComplexHeatmap - How to change fontsize of rowAnnotation

I am trying to work get the fontsize of a heatmap rowannotation customized. How can I achieve this endeavor?

Here is my code:

mark_at = which(rownames(mat_ht) %in% gene_names_interesting_in_clusters) # look up label names which should be displayed

ha = rowAnnotation(text = anno_mark(at = mark_at, labels = gene_names_interesting_in_clusters),annotation_name_gp = gpar(fontsize = 2)) # set rowAnnotations and change fontsize

if (save_plots=='yes') {
    tiff(file="heatmap_genes_of_upreg_upon_aRinp100test.tiff",width = 6, height = 6, units = 'in',res = 600)
} 
Heatmap(mat_ht, name = "Z-score", cluster_rows = TRUE, cluster_columns = FALSE,  right_annotation = ha,
        show_row_names = FALSE, show_column_names = FALSE,row_names_gp = gpar(fontsize = 4), km=16,row_title_gp = gpar(fontsize = 4)) 
        if (save_plots=='yes') {
            dev.off()
        } # create heatmap

Many thanks in advance!

r complexheatmap

Try tweaking the gp of the rowAnnotation instead of tweaking the annotation_name_gp - that might do the trick.

Thank you. What exactly do you mean? Changing ha = rowAnnotation(text = anno_mark(at = mark_at, labels = gene_names_interesting_in_clusters),annotation_name_gp = gpar(fontsize = 2)) to ha = rowAnnotation(text = anno_mark(at = mark_at, labels = gene_names_interesting_in_clusters),gp = gpar(fontsize = 2))?

Yes. The solution to most things with ComplexHeatmap is to play around with parameters.

It doesn't work. The annotation labels are still in a default fontsize. I cant find a way to set the fontsize.

Thanks for the input. Unfortunately, that didn't help either. I appreciate any other tips.

Thank you

I still cannot find a way. It seems to be an easy to solve issue and I was trying any possible combination with the aforementioned gp=gpar(fontsize=...) solutions. However, I wasnt able to resolve it. Can please someone help? Thank you

Please do not add answers unless you're actually answering the question. I've moved your post to a comment.

1 answer

set.seed(1)
m = matrix(rnorm(100), nrow = 10)
rownames(m) = 1:10

# normal
ha = rowAnnotation(foo = anno_mark(at=1:nrow(m), labels=rownames(m)))
Heatmap(m, name = "mat", cluster_rows = FALSE, right_annotation = ha, show_row_names = FALSE)

enter image description here

# bigger labels
ha = rowAnnotation(foo = anno_mark(at=1:nrow(m), labels=rownames(m), labels_gp = gpar(fontsize=20)))
Heatmap(m, name = "mat", cluster_rows = FALSE, right_annotation = ha, show_row_names = FALSE)

enter image description here

The labels_gp within anno_block is the key.

A small educational note: if an answer was helpful, you should upvote it; if the answer resolved your question, you should mark it as accepted. You can accept more than one answer if they work. This will help future users that might find this post find the right answer.

upvote_bookmark_accept

Log in to answer this question.