Given a clustering of some data, and some ideal order we'd like to use to visualize it, reorder (but do not modify) the clustering to be as consistent as possible with this ideal order.

reorder_hclust(clusters, order)

## Arguments

clusters The existing clustering of the data. The ideal order we'd like to see the data in.

## Value

A reordered clustering which is consistent, wherever possible, the ideal order.

## Examples

clusters <- hclust(dist(mtcars))
clusters$order #> [1] 31 17 15 16 29 7 24 5 25 4 6 14 12 13 22 23 19 20 18 26 30 28 9 32 3 #> [26] 21 27 8 1 2 10 11clusters <- slanter::reorder_hclust(clusters, 1:length(clusters$order))
clusters\$order
#>  [1]  4  6 12 13 14 22 23  1  2 10 11  8  9  3 21 27 32 28 30 19 20 18 26 15 16
#> [26] 17  5 25  7 24 29 31