Heatmap.2 - flip dendrogram so control group appears on LHS?
1
0
Entering edit mode
7.1 years ago
Biogeek ▴ 470

I am wanting to flip the dendrogram above my heatmap so that the SC group appears on the left of the heatmap and the IO group appears on the right as opposed to the left. Is there anyway I can do this without removing the dendrograms? The SC is the control group and as such it seems logical that it should be shown first.

Thank you for your input.

Heatmap example

R heatmap • 11k views
ADD COMMENT
0
Entering edit mode

Is the Colv argument from the function not working?

Rowv determines if and how the row dendrogram should be reordered. By default, it is TRUE, which implies dendrogram is computed and reordered based on row means. If NULL or FALSE, then no dendrogram is computed and no reordering is done. If a dendrogram, then it is used "as-is", ie without any reordering. If a vector of integers, then dendrogram is computed and reordered based on the order of the vector.

Colv determines if and how the column dendrogram should be reordered. Has the options as the Rowv argument above and additionally when x is a square matrix, Colv="Rowv" means that columns should be treated identically to the rows.

Try to feed it a vector of integers and see what happens (e.g. c(4, 5, 6, 1, 2, 3)).

ADD REPLY
0
Entering edit mode

Hey mate,

I tried Colv but it omits the upset dendogram. Would prefer to keep it o show the distances/ similarity.

When you say feed it a vector can you elaborate? I give heatmap.2 a matrix of values. Even if I reorder the matrix columns, it still puts the heatmap as is. 😞

ADD REPLY
0
Entering edit mode

Have you looked at the re-order function? Try adding this to the heatmap.2 command and see what happens: reorderfun=function(d,w) reorder(d, w, agglo.FUN=mean)

You can also try changing the distance and linkage functions (and use different combinations of these):

Euclidean distance

distfun=function(x) dist(x, method="euclidean")

1-Pearson correlation distance

distfun=function(x) as.dist(1-cor(t(x)))

Ward's linkage

hclustfun=function(x) hclust(x, method="ward.D2")

Complete linkge

hclustfun=function(x) hclust(x, method="complete")
ADD REPLY
1
Entering edit mode
7.1 years ago
e.rempel ★ 1.1k

Hi,

Kevin already posted about reorder function. In my previous answer I provided one example how to choose weights for specific branches in dendrogram.

ADD COMMENT
0
Entering edit mode

Have tried these methods, but no luck, Them methods seem to only adjust the rows around? The closest I have got is feeding Vcol = (4,5,6,1,2,3), however, the upper dendrogram becomes flat and doesn't offer any insight into similarity of samples.

ADD REPLY
0
Entering edit mode

Why not flip it and get the mirror image in a graphics editor? You're not manipulating the result at all in that scenario.

I have actually been asked this question again and again by people. Left-to-right doesn't mean that much in a dendrogram. It's the height and connections of the bars that's important

ADD REPLY
0
Entering edit mode

I will see what I can do. Would it matter if I didn't provide the top dendrogram (Vcol = FALSE) . That command allows me to have control on LHS but just no dendrogram.

ADD REPLY
1
Entering edit mode

Yes, that's the trade off: if you tell the function that you want to fix the position of the samples, then it infers that you don't want it to perform the clustering. This assumption even follows through to ComplexHeatmap.

The only other thing that I'd suggest is to edit the heatmap.2 code itself.

ADD REPLY
1
Entering edit mode

I just spotted this, in fact, where you can flip your dendrogram using just the rev() command. Within the heatmap.2 function, you could possibly try this with:

distfun=function(x) dist(x, method="euclidean")
hclustfun=function(x) rev(hclust(x, method="ward.D2"))
ADD REPLY
0
Entering edit mode

heatmap.2(lc2, col=colfunc(200),Colv= F, main = "Sample",dendrogram = "both", scale = "none", trace = "none", keysize = 1.0, key.ylab = NA, density.info = "none",key.xlab = "Z-score", labRow = "", breaks = seq(-2, 2, length.out = 201)))

My code above, is there a way to do this in that? I'm just using the default heatmap.2 command.

ADD REPLY
1
Entering edit mode

It accepted hclustfun=function(x) rev(as.dendrogram(hclust(x, method="ward.D2"))) as the hclust function but just plotted the same thing (at least using my test data).

One other thing to try is the revC parameter that already exists in heatmap.2. It accepts TRUE or FALSE

ADD REPLY
0
Entering edit mode

Sorry for being ignorant. I'm unsure how I can feed the above hclustfun into my code. Can you explain how I incorporate that into heatmap.2(....)?Thanks.

ADD REPLY
1
Entering edit mode

For both of the parameters that I mention, just use them like this:

heatmap.2(..., revC=TRUE, ...)

heatmap.2(..., hclustfun=function(x) rev(as.dendrogram(hclust(x, method="ward.D2"))), ...)
ADD REPLY

Login before adding your answer.

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