Learn R Programming

dendextend (version 1.13.4)

match_order_dendrogram_by_old_order: Adjust the order of one dendrogram based on another (using order)

Description

Takes one dendrogram and adjusts its order leaves valeus based on the order of another dendrogram. The values are matached based on the order of the two dendrograms.

This allows for faster entanglement running time, since we can be sure that the leaves order is just as using their labels.

This is a function is FASTER than match_order_by_labels, but it assumes that the order and the labels of the two trees are matching!!

This will allow for a faster calculation of entanglement.

Usage

match_order_dendrogram_by_old_order(
  dend_change,
  dend_template,
  dend_change_old_order,
  check_that_labels_match = FALSE,
  check_that_leaves_order_match = FALSE
)

Arguments

dend_change

tree object (dendrogram)

dend_template

tree object (dendrogram)

dend_change_old_order

a numeric vector with the order of leaves in dend_change (at least before it was changes for some reason). This is the vector based on which we adjust the new values of dend_change.

check_that_labels_match

logical (FALSE). If to check that the labels in the two dendrogram match. (if they do not, the function aborts)

check_that_leaves_order_match

logical (FALSE). If to check that the order in the two dendrogram match. (if they do not, the function aborts)

Value

Returns dend_change after adjusting its order values to be like dend_template.

See Also

entanglement , tanglegram, match_order_by_labels

Examples

Run this code
# NOT RUN {
dend <- USArrests[1:4, ] %>%
  dist() %>%
  hclust() %>%
  as.dendrogram()
order.dendrogram(dend) #  c(4L, 3L, 1L, 2L)


# Watch this!
dend_changed <- dend
dend_changed <- rev(dend_changed)
expect_false(identical(order.dendrogram(dend_changed), order.dendrogram(dend)))
# we keep the order of dend_change, so that the leaves order are synced
# with their labels JUST LIKE dend:
old_dend_changed_order <- order.dendrogram(dend_changed)
# now we change dend_changed leaves order values:
order.dendrogram(dend_changed) <- 1:4
# and we can fix them again, based on their old kept leaves order:
dend_changed <- match_order_dendrogram_by_old_order(
  dend_changed, dend,
  old_dend_changed_order
)
expect_identical(order.dendrogram(dend_changed), order.dendrogram(dend))
# }

Run the code above in your browser using DataLab