Question: Heatmap.2 - flip dendrogram so control group appears on LHS?
0
gravatar for Biogeek
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 example

heatmap R • 4.5k views
ADD COMMENTlink 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. 😞

ADD REPLYlink written 2.6 years ago by Biogeek380

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 REPLYlink modified 2.6 years ago • written 2.6 years ago by Kevin Blighe60k
1
gravatar for e.rempel
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.

ADD COMMENTlink written 2.6 years ago by e.rempel820

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 REPLYlink written 2.6 years ago by Biogeek380

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

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 REPLYlink written 2.6 years ago by Biogeek380
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.

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

ADD REPLYlink written 2.6 years ago by Biogeek380
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

ADD REPLYlink written 2.6 years ago by Kevin Blighe60k

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 REPLYlink written 2.6 years ago by Biogeek380
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
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1199 users visited in the last hour