Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

colour labels in the dendrograms with zero height terminal branches #3

Closed
varmara opened this issue Aug 25, 2014 · 3 comments
Closed

Comments

@varmara
Copy link

varmara commented Aug 25, 2014

Hello, Tal,

I'm trying to colour labels in the two dendrograms that contain terminal branches with zero height.
One of the dendrograms is coloured successfully, the other one fails with an error message from cutree_1k.dendrogram.

Does it happen because the first dendrogram contains the branches with zero height only with 2 leaves, while the other one has up to 4 leaves in such branches?

Could you suggest any solution?

With best regards,

Marina

Here is the link to the Rdata and the code

easy_mod <- color_labels(easy, col = easy_cols) # is coloured successfuly
par(mar = c(4, 2, 2, 10))
plot(easy_mod, horiz = T)

hard_mod <- color_labels(hard, col = hard_cols) # fails to be coloured

# Error in if (length(col) < k) { : missing value where TRUE/FALSE needed
# In addition: Warning messages:
#1: In cutree_1k.dendrogram(k = x, ...) :
#   Couldn't cut the tree - returning NA.
#2: In cutree_1k.dendrogram(k = x, ...) :
#   No cut exists for creating 92 clusters.  The possible range for clusters is: [0-76]
@talgalili
Copy link
Owner

Dear Varmara,
Thank you for the bug report!

The short answer is that I fixed this issue, and you can use the fixed code in dendextend version 0.17.3, which is now on github (it will take another month or so before I'll upload it to CRAN).
Please see the README file, to see how to install dendextend from github:
https://github.com/talgalili/dendextend/blob/master/README.md
(and comment here if you have any problems with it).

The longer answer is that:
I made sure color_labels will be more robust for cases where you color all the labels (and not per cluster), so it won't have to go through cutree (this will make your example work).

Here is a self contained example that shouldn't work in 0.17.2, but now works in 0.17.3:

dend_flat <- structure(list(structure(88L, members = 1L, height = 0, label = "mel Ch   m pe", leaf = TRUE, value = 83), 
                            structure(list(structure(92L, members = 1L, height = 0, label = "mel Ch   f fo", leaf = TRUE, value = 84), 
                                           structure(list(structure(90L, members = 1L, height = 0, label = "mel Ch   f he", leaf = TRUE, value = 85), 
                                                          structure(list(structure(84L, label = "mel Ch   m he", members = 1L, height = 0, leaf = TRUE, value = 86), 
                                                                         structure(86L, label = "mel Ch   m fo", members = 1L, height = 0, leaf = TRUE, value = 87)), members = 2L, midpoint = 0.5, height = 0, value = 86.5)), members = 3L, midpoint = 0.75, height = 0, value = 85.75)), members = 4L, midpoint = 0.875, height = 0, value = 84.875)), members = 5L, midpoint = 0.9375, height = 0.0697674418604651, value = 83.9375, class = "dendrogram")

dend_flat %>% color_labels %>% plot # doesn't work in 0.17.2, but it is fixed in 0.17.3
dend_flat %>% color_labels(col = 1:2) %>% plot # doesn't work in 0.17.2, but it is fixed in 0.17.3

Your report has actually surfaced another issue in cutree - so thanks again! (I will look at this issue again next week)

@varmara
Copy link
Author

varmara commented Aug 26, 2014

Thanks, it works fine now

@talgalili
Copy link
Owner

My pleasure varmara :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants