Changing LFC font size on Complex Heatmap
1
0
Entering edit mode
13 months ago

I am having trouble with the font size of a complex heatmap. I created it as follow:

l2_val <- as.matrix(genes$log2FoldChange)
h2 <- Heatmap(l2_val,row_km = 10,row_names_gp = gpar(fontsize = 5),row_labels = genes$external_gene_name, 
        cluster_rows = F, name="logFC", top_annotation = ha, col = col_logFC,
        cell_fun = function(j, i, x, y, w, h, col) { # add text to each grid
          grid.text(round(l2_val[i, j],2), x, y)
        })

The result is the following:

enter image description here

How can I make the numbers smaller, so that they can fit in the cells?

R complexheatmap deseq2 • 657 views
ADD COMMENT
0
Entering edit mode
13 months ago
bk11 ★ 3.0k

Please change grid.text(round(l2_val[i, j],2), x, y) section of your code into grid.text(sprintf("%.1f", l2_val[i, j]), x, y, gp = gpar(fontsize = 20)). Your final code will be like this. I have not tried it though.

l2_val <- as.matrix(genes$log2FoldChange)
h2 <- Heatmap(l2_val,row_km = 10,row_names_gp = gpar(fontsize = 5),row_labels = genes$external_gene_name, 
        cluster_rows = F, name="logFC", top_annotation = ha, col = col_logFC,
        cell_fun = function(j, i, x, y, width, height, fill) { # add text to each grid
          grid.text(sprintf("%.1f", l2_val[i, j]), x, y, gp = gpar(fontsize = 20))
        })
ADD COMMENT

Login before adding your answer.

Traffic: 2018 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6