talgalili / heatmaply

Interactive Heat Maps for R Using plotly
377 stars 73 forks source link

Cannot Reorder Heatmap Without Displaying Dendrogram #107

Closed r-velde closed 5 years ago

r-velde commented 7 years ago

I would like to cluster the rows without displaying the rows dendrogram.

Thanks

talgalili commented 7 years ago

I'm wondering how this should be done. Should there be a special parameter to set this, or should this be based on one of the options passed to Rowv/Colv/dendrogram? Once this is set, probably the easiest way to implement is to not pass the dendrogram to the subplot function but instead pass an empty object through.

@Alanocallaghan - what do you think?

Also, this issue can be related to #44 .

alanocallaghan commented 7 years ago

I think a different parameter makes most sense, to avoid "overloading" Rowv. Perhaps we should add a new cluster argument and deprecate dendrogram in order to make this clear.

ie, heatmaply(mtcars, cluster="both", show_row_dend=FALSE)

talgalili commented 7 years ago

mmm, I have two reservations regarding your suggestion: 1) I would prefer to keep backward compatibility with heatmap.2 (which can be done with you suggestion) and, 2) There are methods in seriation for ordering a matrix, that are "better" than using the order from the dendrogram. So if we know that we are omitting the dendrogram, we might as well expose these other methods, i.e.: #57 ).

I think that in the meantime, the simpler solution is to add a 2d logical argument (we can call it show_dend). Where c(T,T) will mean that both dendrograms are displayed, while something like c(T,F) will mean that only the row dendrogram is plotted (and the column dend is replaced by a blank plot). This solution could remain consistent with future extensions for the row/col ordering method. In general, it would make sense to refactor the documentation / arguments list a bit more. I think we should do it before releasing version 1.0.0 (which will happen once, hopefully, our paper is accepted).

Thoughts?

alanocallaghan commented 7 years ago

I don't have particularly strong feelings about this, so I'd go ahead with what you've suggested as it sounds reasonable.

Long term it would be good to try to break elements out into separate functions as currently there looks to be about 70 arguments, and this is only likely to grow. Perhaps we could make classes for dendrogram options, side color options, and main heatmap options (heatmapr already accomplishes this last part). The difficulty there is keeping compatibility without maintaining the same arguments in multiple places (in most cases) but also simplifying the interface. I'll make a separate issue for this tomorrow

nuriaserra commented 6 years ago

Hello,

I would also like to reorder the heatmap but don't display the dendrogram, and I thing the show_dend argument is a good solution. Have you developed it already?

Thank you,

Best,

Núria

talgalili commented 6 years ago

I've not developed it yet, I apologize.

----------------Contact Details:------------------------------------------------------- Tal Galili, Ph.D. in Statistics

Tal.Galili@gmail.com

www.r-statistics.com (English) www.biostatistics.co.il (Hebrew) | www.talgalili.com (Hebrew)

On Fri, Jul 13, 2018 at 5:38 PM, nuriaserra notifications@github.com wrote:

Hello,

I would also like to reorder the heatmap but don't display the dendrogram, and I thing the show_dend argument is a good solution. Have you developed it already?

Thank you,

Best,

Núria

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/talgalili/heatmaply/issues/107#issuecomment-404852784, or mute the thread https://github.com/notifications/unsubscribe-auth/AA7khkn7YZldY0RxhU04n41yu9JRTD7Jks5uGLDhgaJpZM4Pqsi2 .

nuriaserra commented 6 years ago

Ok, no worries. Do you plan to develop it soon?

Nuria Serra Intern

Gregor Mendel Institute of Molecular Plant Biology GmbH Dr. Bohr-Gasse 3, 1030 Vienna, Austria nuria.serra@gmi.oeaw.ac.at http://www.gmi.oeaw.ac.at

[cid:gmisig_231_92997f80-ec0b-4736-9e1e-b20adcb9ca37.png]


From: Tal Galili notifications@github.com Sent: 13 July 2018 16:41:27 To: talgalili/heatmaply Cc: Serra, Nuria; Comment Subject: Re: [talgalili/heatmaply] Cannot Reorder Heatmap Without Displaying Dendrogram (#107)

I've not developed it yet, I apologize.

----------------Contact Details:------------------------------------------------------- Tal Galili, Ph.D. in Statistics

Tal.Galili@gmail.com

www.r-statistics.com (English) www.biostatistics.co.il (Hebrew) | www.talgalili.com (Hebrew)

On Fri, Jul 13, 2018 at 5:38 PM, nuriaserra notifications@github.com wrote:

Hello,

I would also like to reorder the heatmap but don't display the dendrogram, and I thing the show_dend argument is a good solution. Have you developed it already?

Thank you,

Best,

Núria

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/talgalili/heatmaply/issues/107#issuecomment-404852784, or mute the thread https://github.com/notifications/unsubscribe-auth/AA7khkn7YZldY0RxhU04n41yu9JRTD7Jks5uGLDhgaJpZM4Pqsi2 .

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/talgalili/heatmaply/issues/107#issuecomment-404853655, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AlHWpZbNt3K_GQ5ZHbmQAcNZ2l-L9an7ks5uGLGXgaJpZM4Pqsi2.

talgalili commented 6 years ago

Not in the near future. The best solution is to reorder the table beforehand using seriation and then supply it to heatmaply with dendrogram=FALSE.

nuriaserra commented 6 years ago

Do you mean like this?

obj1 = heatmapr(matrix1, seriation = "mean") heatmaply(obj1, dendrogram = "none")

If I do it like this, I obtain a very strange heatmap with points instead of cells, and the dendrogram is still present in both rows and columns... trial

koalive commented 6 years ago

Hi,

I think that would be a great feature to have. I just wanted to share a quick and dirty workaround in the meantime: make the dendrograms white. Something like the following:

library(heatmaply)
library(dendextend)

# Replace with your data
X = iris[1:10,1:4] 
# Compute the row dendrograms as they would be by default with heatmaply
dist_dend <- dist(X)
row_dend <- as.dendrogram(hclust(dist_dend))
row_dend <- seriate_dendrogram(row_dend, dist_dend, method = "OLO")
# Make them white
row_dend <- row_dend %>% set("branches_col", "white")

# Plot
heatmaply(X, Rowv = row_dend, file = "test1.png")
heatmaply(X, file = "test2.png")

However the legend ends up a bit far from the plot. I think if that's really a problem, the approach suggested by @talgalili would be better (compute the dendrograms, reorder your data based on the dendrograms, plot with dendrogram=FALSE and without providing the dendrograms).

Cheers.

simonroome commented 5 years ago

Hi,

Thanks for the great package. I'd just like to add that I would also love a show_dend argument that can be set to FALSE, instead of having to do the seriate and dendrogram = FALSE workaround. Just wondering if you have any plans for developing this in the near future.

Cheers

talgalili commented 5 years ago

This would take some time to solve, so I suspect it won't happen in the near future. But I'm fine keeping this as an issue that is open for when we'll get to it (or if someone else would like to help out).

Cheers, T

On Wed, Jul 31, 2019 at 9:08 PM Simon Roome notifications@github.com wrote:

Hi,

Thanks for the great package. I'd just like to add that I would also love a show_dend argument that can be set to FALSE, instead of having to do the seriate and dendrogram = FALSE workaround. Just wondering if you have any plans for developing this in the near future.

Cheers

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/talgalili/heatmaply/issues/107?email_source=notifications&email_token=AAHOJBT7NAUTUOQP5CDWMBTQCHII7A5CNFSM4D5KZC3KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD3ICXYA#issuecomment-516959200, or mute the thread https://github.com/notifications/unsubscribe-auth/AAHOJBQCBRLSB7PNAROXR73QCHII7ANCNFSM4D5KZC3A .

alanocallaghan commented 5 years ago

@r-velde @simonroome @koalive @nuriaserra, I've implemented this very quickly as a simple option on the show_dend branch. Displaying the dendrograms is controlled by the argument show_dendrogram, which is a length 2 logical vector controlling whether the row and column dendrograms are displayed. You can install and test via install_github("talgalili/heatmaply", ref = "show_dend")

You can also supply a length 1 logical vector and this will be repeated to become a length 2 vector.

Tal I know this isn't as sophisticated as you suggested but it's probably okay for a lot of use cases.

alanocallaghan commented 5 years ago

eg,

library("heatmaply")
heatmaply(scale(mtcars), show_dendrogram=c(TRUE, FALSE))` # do not display column dendrogram
talgalili commented 5 years ago

Hi @Alanocallaghan , I think this functionality you added (here) is just duplicating the behavior of: dendrogram = c("both", "row", "column", "none")

i.e.: using show_dendrogram=c(TRUE, FALSE) is just like using dendrogram = c("row")

So I think adding another parameter that does exactly the same thing is dendrogram is not advisable. If you think it is good to add the logical behavior, you can just add this behavior to dendrogram so that it would also know how to treat logical vectors. This way you'll get the same outcome without adding another parameter.

Either way, I think the issue the people here want is to not show dendrograms but to have the matrix ordered (which is currently not implemented, also not in your solution). So doing this, I suspect, is not going to be very helpful.

What do you think?

alanocallaghan commented 5 years ago

It's not doing the same thing. dendrogram controls, via Rowv and Colv, whether the dendrograms are computed and used to re-order the data, show_dendrogram controls whether they are drawn.

alanocallaghan commented 5 years ago

Either way, I think the issue the people here want is to not show dendrograms but to have the matrix ordered (which is currently not implemented, also not in your solution).

This is exactly what I have implemented. By setting colDend and/or rowDend to NULL at this point (after they've been computed and the data re-ordered) we cause them not to be displayed.

talgalili commented 5 years ago

Thanks Allan, interesting. Could you please copy-paste a screenshot of how the end result looks like for your code? (I get little computer access time, so a screenshot would help me - thanks)

On Thu, Aug 1, 2019 at 6:28 PM Alanocallaghan notifications@github.com wrote:

Either way, I think the issue the people here want is to not show dendrograms but to have the matrix ordered (which is currently not implemented, also not in your solution).

This is exactly what I have implemented. By setting colDend and/or rowDend to NULL at this point (after they've been computed and the data re-ordered) we cause them not to be displayed.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/talgalili/heatmaply/issues/107?email_source=notifications&email_token=AAHOJBXERS5AUNR5EQQZUI3QCLPGTA5CNFSM4D5KZC3KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD3KSGMI#issuecomment-517284657, or mute the thread https://github.com/notifications/unsubscribe-auth/AAHOJBSSQ2XCFQIRED75LETQCLPGTANCNFSM4D5KZC3A .

alanocallaghan commented 5 years ago

No clustering:

heatmaply(scale(mtcars), dend="none") Screenshot from 2019-08-01 20-36-10

Clustering rows & columns, show both dendrograms

heatmaply(scale(mtcars)) Screenshot from 2019-08-01 20-37-07

Clustering rows & columns, show no dendrograms

heatmaply(scale(mtcars), show_dend=c(FALSE, FALSE)) Screenshot from 2019-08-01 20-36-52

Clustering rows & columns, show row dend only

heatmaply(scale(mtcars), show_dend=c(TRUE, FALSE)) Screenshot from 2019-08-01 20-37-18

Clustering rows & columns, show column dend only

heatmaply(scale(mtcars), show_dend=c(FALSE, TRUE) Screenshot from 2019-08-01 20-37-41

alanocallaghan commented 5 years ago

No worries. If this works for everybody, happy to merge and leave it at that (although I will update the documentation first to make clear the difference between dendrogram and show_dendrogram)

talgalili commented 5 years ago

This is great @Alanocallaghan ! Sure thing, please merge this into the main branch (and make sure to update the doc and the vignette). This is a great addition to the package.

alanocallaghan commented 5 years ago

Cool, closing this now (#215) @r-velde @simonroome @koalive @nuriaserra, if you have any further comments/requests on this topic feel free to add here