Question: Heatmap.2 - flip dendrogram so control group appears on LHS?
0
2.6 years ago by
Biogeek380
Biogeek380 wrote:

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 R • 4.5k views
modified 2.6 years ago by e.rempel820 • written 2.6 years ago by Biogeek380

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 REPLYlink modified 2.6 years ago • written 2.6 years ago by Selenocysteine600

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. ðŸ˜ž

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)))
``````

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

``````hclustfun=function(x) hclust(x, method="complete")
``````
ADD REPLYlink modified 2.6 years ago • written 2.6 years ago by Kevin Blighe60k
1
2.6 years ago by
e.rempel820
Germany, Heidelberg, COS
e.rempel820 wrote:

Hi,

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

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.

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

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.

1

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.

1

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 REPLYlink modified 2.6 years ago • written 2.6 years ago by Kevin Blighe60k

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.

1

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

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.

1

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 REPLYlink modified 2.6 years ago • written 2.6 years ago by Kevin Blighe60k