Heatmap in R; how to change the order of Row names
1
0
Entering edit mode
16 months ago
hellokwmin • 0

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:

enter image description here

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.

R ComplexHeatmap • 1.0k views
ADD COMMENT
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

Alternatively you could use ggplots geom_tile to make the heatmap. Then you could set facet_wrap(~Family), and change the order by setting the factor

df$Family = factor(df$Family, levels=c( ....   ))
ADD REPLY
4
Entering edit mode
16 months ago
bk11 ★ 3.0k

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)

enter image description here

ADD COMMENT

Login before adding your answer.

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