talgalili / dendextend

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

Bug in get_subdendrograms #104

Closed chasemc closed 3 years ago

chasemc commented 3 years ago

Describe the bug get_subdendrograms() only works if dendrogram has numeric labels. The example in the documentation works but only by chance.

To Reproduce

Code adapted from the example in the documentation

This seems to work:

library(dendextend)

iris[1:10, -5] %>%
  dist() %>%
  hclust() %>%
  as.dendrogram() %>%
  set("labels_to_character") %>%
  color_branches(k = 5) %>% 
  #dendextend::set_labels(paste0("a",labels(.) ))%>% 
  get_subdendrograms(5)

But un-commenting the line that adds an 'a' to each of the labels reveals it doesn't work

library(dendextend)

iris[1:10, -5] %>%
  dist() %>%
  hclust() %>%
  as.dendrogram() %>%
  set("labels_to_character") %>%
  color_branches(k = 5) %>% 
  dendextend::set_labels(paste0("a",labels(.) ))%>% 
  get_subdendrograms(5)

I've figured out the fix and will send a PR.