talgalili / dendextend

Extending R's Dendrogram Functionality
152 stars 28 forks source link

find_dendrogram function broken #102

Closed jkh1 closed 4 years ago

jkh1 commented 4 years ago

The find_dendrogram function appears broken. The example given in the doc returns just a single branch labelled '1'. See below. I think the reason may be that the function uses unlist(dend) which returns a numeric vector and tries to match it to selected_labels which is a logical vector. This is with R 4.0.2 and dendextend 1.13.4

# define dendrogram object to play with:
dend <- iris[, -5] %>%
  dist() %>%
  hclust() %>%
  as.dendrogram() %>%
  set("labels_to_character") %>%
  color_branches(k = 5)
first.subdend.only <- cutree(dend, 4) == 1
sub.dend <- find_dendrogram(dend, first.subdend.only)
# Plotting the result
par(mfrow = c(1, 2))
plot(dend, main = "Original dendrogram")
plot(sub.dend, main = "First subdendrogram")

results in image

talgalili commented 4 years ago

Thanks for the bug report @jkh1 The version on github (1.14.0) - now has a fixed version of the function. The documentation was fixed to now explain how the function can/should be used. Please check and let me know if it doesn't what you want.

Cheers, T

jkh1 commented 4 years ago

Thanks @talgalili I think I have misunderstood what this function does. I thought it would be doing the same thing as ape::keep.tip().

talgalili commented 4 years ago

What does ape::keep.tip() do? Is it similar to prune? (which emulates drop.tip)

On Fri, Aug 14, 2020 at 2:50 PM Jean-Karim Hériché notifications@github.com wrote:

Thanks @talgalili https://github.com/talgalili I think I have misunderstood what this function does. I thought it would be doing the same thing as ape::keep.tip().

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/talgalili/dendextend/issues/102#issuecomment-674037064, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHOJBTIA4KFR2VB62DSU43SAUQIJANCNFSM4P7HB64Q .

jkh1 commented 4 years ago

keep.tip gets the tree induced by the selected leaves so it is complementary to drop.tip/prune. One can work with prune, it's just that in my case it's simpler to work with what I need to keep than with what I need removed.

talgalili commented 4 years ago

Got it. Do you want to use prune to create a dendrogram version of keep.tip? If so, please post it here and I'll add it to the package.

On Sat, Aug 15, 2020, 19:02 Jean-Karim Hériché notifications@github.com wrote:

keep.tip gets the tree induced by the selected leaves so it is complementary to drop.tip/prune. One can work with prune, it's just that in my case it's simpler to work with what I need to keep than with what I need removed.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/talgalili/dendextend/issues/102#issuecomment-674415882, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHOJBUZRRXPZ25BL7SV77DSA2WQJANCNFSM4P7HB64Q .