talgalili / dendextend

Extending R's Dendrogram Functionality

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

find_dendrogram function broken

jkh1 opened this issue · comments

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

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

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

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.