if (FALSE) {
# Figures recreated from 'Shuffle & untangle: novel untangle
# methods for solving the tanglegram layout problem' (Nguyen et al. 2022)
library(tidyverse)
example_labels <- c("Versicolor 90", "Versicolor 54", "Versicolor 81",
"Versicolor 63", "Versicolor 72", "Versicolor 99", "Virginica 135",
"Virginica 117", "Virginica 126", "Virginica 108", "Virginica 144",
"Setosa 27", "Setosa 18", "Setosa 36", "Setosa 45", "Setosa 9")
iris_modified <-
iris %>%
mutate(Row = row_number()) %>%
mutate(Label = paste(str_to_title(Species), Row)) %>%
filter(Label %in% example_labels)
iris_numeric <- iris_modified[,1:4]
rownames(iris_numeric) <- iris_modified$Label
# Single Linkage vs. Complete Linkage comparison (Fig. 1)
dend1 <- as.dendrogram(hclust(dist(iris_numeric), method = "single"))
dend2 <- as.dendrogram(hclust(dist(iris_numeric), method = "complete"))
tanglegram(dend1, dend2,
color_lines = TRUE,
lwd = 2,
margin_inner = 6) # Good.
entanglement(dend1, dend2, L = 2) # 0.207
# The step2side algorithm (Fig. 2)
result <- untangle_step_rotate_2side(dend1, dend2)
tanglegram(result[[1]], result[[2]],
color_lines = TRUE,
lwd = 2,
margin_inner = 6) # Better...
entanglement(result[[1]], result[[2]], L = 2) # 0.185
# The stepBothSides algorithm (Fig. 4)
result <- untangle_step_rotate_both_side(dend1, dend2)
tanglegram(result[[1]], result[[2]],
color_lines = TRUE,
lwd = 2,
margin_inner = 6,
lty = 1) # PERFECT.
entanglement(result[[1]], result[[2]], L = 2) # 0.000
}
Run the code above in your browser using DataLab