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.
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
• 1,254 views
•
link
1 answer
What you can do is:
- add some space between geneid and symbol:
rownames(df) <- paste0(df$geneid," - ",df$SYMBOL) - Increase the height of your heatmap either globally (
heatmap_height,height,..) or by tweaking the height of each cell (e.g.cell_fun)
• 0 views
•
link
Log in to answer this question.
The geneid is not informative to readers anyways, just keep the symbol although you have some NAs...