Rotate a branch in a tree so that the locations of two bundles of leaves are flipped.
flip_leaves(dend, leaves1, leaves2, ...)
A dendrogram object with flipped leaves.
This function is based on a bunch of string manipulation functions. There may be a smarter/better way for doing it...
if (FALSE) { # \dontrun{
dend1 <- USArrests[1:5, ] %>%
dist() %>%
hclust() %>%
as.dendrogram()
dend2 <- flip_leaves(dend1, c(3, 5), c(1, 2))
tanglegram(dend1, dend2)
entanglement(dend1, dend2, L = 2) # 0.4
} # }