plotwithprototypes: Plot Dendrogram with Prototype Labels Added

View source: R/plotfunctions.R

plotwithprototypesR Documentation

Plot Dendrogram with Prototype Labels Added

Description

Makes a plot of the dendrogram (using plot.hclust) and adds labels of prototypes on the interior nodes of a dendrogram.

Usage

plotwithprototypes(
  hc,
  imerge = -seq(n),
  labels = NULL,
  bgcol = "white",
  font = 1,
  col = 1,
  cex = 1,
  ...
)

Arguments

hc

an object of class protoclust (as returned by the function protoclust)

imerge

a vector of the nodes whose prototype labels should be added. Interior nodes are numbered from 1 (lowest merge) to n - 1 (highest merge, i.e. the root) and leaf-nodes are negative (so if element i is a prototype for a singleton cluster, then -i is included in imerge). Example: seq(1, n - 1) means every interior node is labeled with a prototype. For larger trees, showing only the prototypes at a given cut may be easier (described more below). Default: -seq(n), meaning all leaf labels and no interior-node labels are shown.

labels

an optional character vector of length n giving the labels of the elements clustered. If not provided, hc$labels is used (if not NULL) or else labels are taken to be seq(n).

bgcol

background color for prototype labels

col, font

color and font of prototype labels

cex

size of prototype label

...

additional arguments to be passed to plot.hclust, such as hang

Details

This function lets one put prototype labels on a dendrogram. The argument imerge controls which interior nodes and leaves are labeled. A convenient choice for the argument imerge is the imerge-output of protocut. This allows one to label a dendrogram with the prototypes of a particular cut. See examples below. This function is called when one writes plot(hc), where hc is an object of class protoclust.

Author(s)

Jacob Bien and Rob Tibshirani

References

Bien, J., and Tibshirani, R. (2011), "Hierarchical Clustering with Prototypes via Minimax Linkage," The Journal of the American Statistical Association, 106(495), 1075-1084.

See Also

protoclust, protocut

Examples


# generate some data:
set.seed(1)
n <- 100
p <- 2
x <- matrix(rnorm(n * p), n, p)
rownames(x) <- paste("A", 1:n, sep="")
d <- dist(x)

# perform minimax linkage clustering:
hc <- protoclust(d)

# cut the tree to yield a 10-cluster clustering:
k <- 10 # number of clusters
cut <- protocut(hc, k=k)
h <- hc$height[n - k]

# plot dendrogram (and show cut):
plotwithprototypes(hc, imerge=cut$imerge)
# or more simply: plot(hc, imerge=cut$imerge)
abline(h=h, lty=2)

# negative values of imerge specify which leaves to label
k2 <- 20 # more clusters... with two singletons
cut2 <- protocut(hc, k=k2)
h2 <- hc$height[n - k2]
plot(hc, hang=-1, imerge=cut2$imerge)
abline(h=h2, lty=2)


protoclust documentation built on April 1, 2022, 9:06 a.m.