View source: R/plotfunctions.R
| plotwithprototypes | R Documentation |
Makes a plot of the dendrogram (using plot.hclust) and adds labels of
prototypes on the interior nodes of a dendrogram.
plotwithprototypes( hc, imerge = -seq(n), labels = NULL, bgcol = "white", font = 1, col = 1, cex = 1, ... )
hc |
an object of class |
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:
|
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 |
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 |
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.
Jacob Bien and Rob Tibshirani
Bien, J., and Tibshirani, R. (2011), "Hierarchical Clustering with Prototypes via Minimax Linkage," The Journal of the American Statistical Association, 106(495), 1075-1084.
protoclust, protocut
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.