Plot a dendrogram of a hierarchical binary cluster tree.
Given tree, a hierarchical binary cluster tree as the output of
linkage, plot a dendrogram of the tree. The number of leaves shown by
the dendrogram plot is limited to p. The default value for p is
30. Set p to 0 to plot all leaves.
The optional outputs are h, t and perm:
Additional input properties can be specified by pairs of properties and values. Known properties are:
"Reorder"
Reorder the leaves of the dendrogram plot using a numerical vector of size n,
the number of leaves. When p is smaller than n, the reordering
cannot break the p groups of leaves.
"Orientation"
Change the orientation of the plot. Available values: top (default),
bottom, left, right.
"CheckCrossing"
Check if the lines of a reordered dendrogram cross each other. Available
values: true (default), false.
"ColorThreshold"
Not implemented.
"Labels"
Use a char, string or cellstr array of size n to set the label for each
leaf; the label is dispayed only for nodes with just one leaf.
See also: cluster, clusterdata, cophenet, inconsistent, linkage, pdist.
The following code
1 y = [4 5; 2 6; 3 7; 8 9; 1 10]; y(:,3) = 1:5; figure (gcf); clf; dendrogram (y);
Produces the following output
ans = 1
and the following figure
| Figure 1 |
|---|
![]() |
The following code
2 v = 2 * rand (30, 1) - 1; d = abs (bsxfun (@minus, v(:, 1), v(:, 1)')); y = linkage (squareform (d, "tovector")); figure (gcf); clf; dendrogram (y);
Produces the following output
ans = 2
and the following figure
| Figure 1 |
|---|
![]() |
The following code
"collapsed tree, find all the leaves of node 5"
X = randn (60, 2);
D = pdist (X);
y = linkage (D, "average");
figure (gcf); clf;
subplot (2, 1, 1);
title ("original tree");
dendrogram (y, 0);
subplot (2, 1, 2);
title ("collapsed tree");
[~, t] = dendrogram (y, 20);
find(t == 5)
Produces the following output
ans = collapsed tree, find all the leaves of node 5
ans =
5 17 38 45
and the following figure
| Figure 1 |
|---|
![]() |
The following code
"optimal leaf order"
X = randn (30, 2);
D = pdist (X);
y = linkage (D, "average");
order = optimalleaforder (y, D);
figure (gcf); clf;
subplot (2, 1, 1);
title ("original leaf order");
dendrogram (y);
subplot (2, 1, 2);
title ("optimal leaf order");
dendrogram (y, "Reorder", order);
Produces the following output
ans = optimal leaf order
and the following figure
| Figure 1 |
|---|
![]() |
The following code
"horizontal orientation and labels"
X = randn (8, 2);
D = pdist (X);
L = ["Snow White"; "Doc"; "Grumpy"; "Happy"; "Sleepy"; "Bashful"; ...
"Sneezy"; "Dopey"];
y = linkage (D, "average");
dendrogram (y, "Orientation", "left", "Labels", L);
Produces the following output
ans = horizontal orientation and labels
and the following figure
| Figure 1 |
|---|
![]() |
Package: statistics