Make rownames more legible in R Heatmap
1
0
Entering edit mode
9 months ago
hellokwmin • 0

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 • 542 views
ADD COMMENT
0
Entering edit mode

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

ADD REPLY
1
Entering edit mode
9 months ago
fracarb8 ★ 1.6k

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)
ADD COMMENT

Login before adding your answer.

Traffic: 1672 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