Cuts a dendrogram tree into several groups by specifying the desired cut height (only a single height!).

cutree_1h.dendrogram(
  dend,
  h,
  order_clusters_as_data = TRUE,
  use_labels_not_values = TRUE,
  warn = dendextend_options("warn"),
  ...
)

Arguments

dend

a dendrogram object

h

numeric scalar (NOT a vector) with a height where the dend should be cut.

order_clusters_as_data

logical, defaults to TRUE. There are two ways by which to order the clusters: 1) By the order of the original data. 2) by the order of the labels in the dendrogram. In order to be consistent with cutree, this is set to TRUE.

use_labels_not_values

logical, defaults to TRUE. If the actual labels of the clusters do not matter - and we want to gain speed (say, 10 times faster) - then use FALSE (gives the "leaves order" instead of their labels.).

warn

logical (default from dendextend_options("warn") is FALSE). Set if warning are to be issued, it is safer to keep this at TRUE, but for keeping the noise down, the default is FALSE.

...

(not currently in use)

Value

cutree_1h.dendrogram returns an integer vector with group memberships

See also

Author

Tal Galili

Examples

hc <- hclust(dist(USArrests[c(1, 6, 13, 20, 23), ]), "ave")
dend <- as.dendrogram(hc)
cutree(hc, h = 50) # on hclust
#>   Alabama  Colorado  Illinois  Maryland Minnesota 
#>         1         1         1         2         3 
cutree_1h.dendrogram(dend, h = 50) # on a dendrogram
#>   Alabama  Colorado  Illinois  Maryland Minnesota 
#>         1         1         1         2         3 

labels(dend)
#> [1] "Minnesota" "Maryland"  "Colorado"  "Alabama"   "Illinois" 

# the default (ordered by original data's order)
cutree_1h.dendrogram(dend, h = 50, order_clusters_as_data = TRUE)
#>   Alabama  Colorado  Illinois  Maryland Minnesota 
#>         1         1         1         2         3 

# A different order of labels - order by their order in the tree
cutree_1h.dendrogram(dend, h = 50, order_clusters_as_data = FALSE)
#> Minnesota  Maryland  Colorado   Alabama  Illinois 
#>         3         2         1         1         1 


# make it faster
if (FALSE) {
library(microbenchmark)
microbenchmark(
  cutree_1h.dendrogram(dend, h = 50),
  cutree_1h.dendrogram(dend, h = 50, use_labels_not_values = FALSE)
)
# 0.8 vs 0.6 sec - for 100 runs
}