Hcoords: Calculates coordinates of nodes from 'hclust' plot

View source: R/bclust.r

HcoordsR Documentation

Calculates coordinates of nodes from 'hclust' plot

Description

Takes the 'hclust' plot and calculates coordinates of ann internal nodes

Usage

  Hcoords(hcl)

Arguments

hcl

hclust object

Details

This function calculates coordinates for each 'hclust' node. Inspired by pvclust::hc2axes().

Hcoords() is useful in connection with Bclust() family (namely, Bclabels()) and also separately. Since Hcoords() allows to label separate nodes, it can be used to label selected clusters (see examples).

See Also

Bclust

Examples


head(Hcoords(hclust(dist(iris[, -5]))))

## simple example: number all nodes
hcl <- hclust(UScitiesD, "ward.D2")
plot(hcl)
hcoo <- Hcoords(hcl)
text(hcoo, labels=1:nrow(hcoo), pos=1)

## complex example:
## find MCCN (Most Close Common Node)
## and label it
plot(hcl)
mat <- Hcl2mat(hcl)
nodes <- 1:nrow(mat) # nodes are rows
colnames(mat) <- hcl$labels
## take two tips and select those rows (nodes) where both present
sel1 <- rowSums(mat[, colnames(mat) %in% c("Denver", "Chicago")]) > 1
## MCCN is the node with both our tips but with the minimum of other tips
MCCN1 <- nodes[sel1][which.min(rowSums(mat[sel1, ]))]
text(hcoo[MCCN1, , drop=FALSE], labels="Eastern + Central", pos=1)
sel2 <- rowSums(mat[, colnames(mat) %in% c("Miami", "Chicago")]) > 1
MCCN2 <- nodes[sel2][which.min(rowSums(mat[sel2, ]))]
text(hcoo[MCCN2, , drop=FALSE], labels="Eastern", pos=1)


shipunov documentation built on Feb. 16, 2023, 9:05 p.m.

Related to Hcoords in shipunov...