This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Make rownames more legible in R Heatmap

Hello,

I am trying to make a heatmap. The dataframe I am using for heatmap is present in A.

enter image description here

Then, I assigned first and fourth columns to rownames using this code:

s = df %>%
  tidyr::unite(rowname, geneid, SYMBOL) %>%
  tibble::column_to_rownames()

The result is shown as (B).

Subsequently, I run this code for plotting heatmap:

as.matrix(s)
color_fun <- colorRamp2(c(-4, 0, 4), c("red", "black", "green"))

Heatmap(s,
        col = color_fun,
        name = "Log2FC",
        row_names_side = "left",
        show_row_names = T,
        show_column_names = F,
        cluster_rows = T,
        cluster_columns = F,
        show_row_dend = F,
        row_names_gp = gpar(fontsize=10),
        width = unit(4, "cm"),
        )

The result is shown as C. But, as you can see in C. the rownames looks very complicated since geneid and symbol is not well separated each other. I would like to make rownames well clear for readers. Is there any code to cope with this issue?

Thank you

r heatmap

The geneid is not informative to readers anyways, just keep the symbol although you have some NAs...

1 answer

What you can do is:

  1. add some space between geneid and symbol: rownames(df) <- paste0(df$geneid," - ",df$SYMBOL)
  2. Increase the height of your heatmap either globally (heatmap_height, height,..) or by tweaking the height of each cell (e.g. cell_fun)

Log in to answer this question.