Heatmap in R; how to change the order of Row names
Hello, Biostars,
I am working on generation of Heatmap.
My R code used for that is:
Heatmap(heat,
name = "Log2",
col = color_fun,
split = df$Family,
cluster_rows = T,
show_row_dend = F,
show_row_names = F,
row_title_side = "left",
row_title_gp = gpar(fontsize = 12, fontface = "bold"),
row_names_side = "left",
row_title_rot = 0,
width = unit(4, "cm"))
And then, I have this figure:
Since I run cluster_row = T function, the order of row is not from 1 to 9. How could I make it from 1 to 9 keeping clustering?
Thank you.
• 2,057 views
•
link
1 answer
You can add cluster_row_slices = F to your code.
head(heat)
C1 C2
R1 -0.56047565 -0.6947070
R2 -0.23017749 -0.2079173
R3 1.55870831 -1.2653964
R4 0.07050839 2.1689560
R5 0.12928774 1.2079620
R6 1.71506499 -1.1231086
Heatmap(heat, name = "Log2", col = color_fun, split = df$Family,
cluster_rows = T, show_row_dend = F, show_row_names = F,
row_title_side = "left", row_title_gp = gpar(fontsize = 12, fontface = "bold"),
row_names_side = "left", row_title_rot = 0, width = unit(4, "cm"), cluster_row_slices = F)
OR you can do km=9 (I m seeing 9 row clusters in your figure) and modify your code like this:-
Heatmap(heat, name = "Log2", col = color_fun, cluster_rows = T,
show_row_dend = F, show_row_names = F, row_title_side = "left",
row_title_gp = gpar(fontsize = 12, fontface = "bold"), row_names_side = "left",
row_title_rot = 0, width = unit(4, "cm"), km=9, cluster_row_slices = F)
• 0 views
•
link
Log in to answer this question.
Hi, One reason this is happening is because of the dendogram. Disable the dendogram for the columns and then check. In most usual cases it sorts the rows order wise
Alternatively you could use ggplots
geom_tileto make the heatmap. Then you could setfacet_wrap(~Family), and change the order by setting the factor