Dendrogram plot - MATLAB dendrogram - MathWorks 中国 (2024)

Dendrogram plot

collapse all in page

Syntax

dendrogram(tree)

dendrogram(tree,Name,Value)

dendrogram(tree,P)

dendrogram(tree,P,Name,Value)

dendrogram(ax,___)

H = dendrogram(___)

[H,T,outperm]= dendrogram(___)

Description

example

dendrogram(tree) generatesa dendrogram plot of the hierarchical binary cluster tree. A dendrogramconsists of many U-shaped lines that connect datapoints in a hierarchical tree. The height of each U representsthe distance between the two data points being connected.

  • If there are 30 or fewer data points in the originaldata set, then each leaf in the dendrogram corresponds to one datapoint.

  • If there are more than 30 data points, then dendrogram collapseslower branches so that there are 30 leaf nodes. As a result, someleaves in the plot correspond to more than one data point.

example

dendrogram(tree,Name,Value) usesadditional options specified by one or more name-value pair arguments.

example

dendrogram(tree,P) generatesa dendrogram plot with no more than P leaf nodes.If there are more than P data points in the originaldata set, then dendrogram collapses the lower branchesof the tree. As a result, some leaves in the plot correspond to morethan one data point.

dendrogram(tree,P,Name,Value) usesadditional options specified by one or more name-value pair arguments.

dendrogram(ax,___) uses the plot axes specified by the axes object ax. Specify ax as the first input argument followed by any of the input argument combinations in the previous syntaxes.

example

H = dendrogram(___) generatesa dendrogram plot and returns a vector of line handles. You can useany of the input arguments from the previous syntaxes.

example

[H,T,outperm]= dendrogram(___) also returns a vector containingthe leaf node number for each object in the original data set, T,and a vector giving the order of the node labels of the leaves asshown in the dendrogram, outperm.

  • It is useful to return T when thenumber of leaf nodes, P, is less than the totalnumber of data points, so that some leaf nodes in the display correspondto multiple data points.

  • The order of the node labels given in outperm isfrom left to right for a horizontal dendrogram, and from bottom totop for a vertical dendrogram.

Examples

collapse all

Plot Dendrogram

Open Live Script

Generate sample data.

Create a hierarchical binary cluster tree using linkage. Then, plot the dendrogram using the default options.

tree = linkage(X,'average');figure()dendrogram(tree)

Dendrogram plot - MATLAB dendrogram- MathWorks 中国 (1)

Specify Dendrogram Leaf Node Order

Open Live Script

Generate sample data.

rng('default') % For reproducibilityX = rand(10,3);

Create a hierarchical binary cluster tree using linkage.

tree = linkage(X,'average');D = pdist(X);leafOrder = optimalleaforder(tree,D)
leafOrder = 1×10 3 7 6 1 4 9 5 8 10 2

Plot the dendrogram using an optimal leaf order.

figure()dendrogram(tree,'Reorder',leafOrder)

Dendrogram plot - MATLAB dendrogram- MathWorks 中国 (2)

The order of the leaf nodes in the dendrogram plot corresponds - from left to right - to the permutation in leafOrder.

Specify Number of Nodes in Dendrogram Plot

Open Live Script

Generate sample data.

rng('default') % For reproducibilityX = rand(100,2);

There are 100 data points in the original data set, X.

Create a hierarchical binary cluster tree using linkage. Then, plot the dendrogram for the complete tree (100 leaf nodes) by setting the input argument P equal to 0.

tree = linkage(X,'average');dendrogram(tree,0)

Dendrogram plot - MATLAB dendrogram- MathWorks 中国 (3)

Now, plot the dendrogram with only 25 leaf nodes. Return the mapping of the original data points to the leaf nodes shown in the plot.

figure[~,T] = dendrogram(tree,25);

Dendrogram plot - MATLAB dendrogram- MathWorks 中国 (4)

List the original data points that are in leaf node 7 of the dendrogram plot.

find(T==7)
ans = 7×1 7 33 60 70 74 76 86

Change Dendrogram Orientation and Line Width

Open Live Script

Generate sample data.

rng('default') % For reproducibilityX = rand(10,3);

Create a hierarchical binary cluster tree using linkage. Then, plot the dendrogram with a vertical orientation, using the default color threshold. Return handles to the lines so you can change the dendrogram line widths.

tree = linkage(X,'average');H = dendrogram(tree,'Orientation','left','ColorThreshold','default');set(H,'LineWidth',2)

Dendrogram plot - MATLAB dendrogram- MathWorks 中国 (5)

Input Arguments

collapse all

treeHierarchical binary cluster tree
matrix returned by linkage

Hierarchical binary cluster tree, specified as an (M –1)-by-3 matrix that you generate using linkage,where M is the number of data points in the originaldata set.

PMaximum number of leaf nodes
30 (default) | positive integer value

Maximum number of leaf nodes to include in the dendrogram plot,specified as a positive integer value.

  • If there are P or fewer data pointsin the original data set, then each leaf in the dendrogram correspondsto one data point.

  • If there are more than P data points,then dendrogram collapses lower branches so thatthere are P leaf nodes. As a result, some leavesin the plot correspond to more than one data point.

    If you do not specify P, then dendrogram uses30 as the maximum number of leaf nodes. To display the complete tree,set P equal to 0.

Data Types: single | double

axAxes for plot
Axes object | UIAxes object

Axes for the plot, specified as an Axes or UIAxes object. If you do not specify ax, then dendrogram creates the plot using the current axes. For more information on creating an axes object, see axes and uiaxes.

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: 'Orientation','left','Reorder',myOrder specifiesa vertical dendrogram with leaves in the order specified by myOrder.

ReorderOrder of leaf nodes
vector

Order of leaf nodes in the dendrogram plot, specified as thecomma-separated pair consisting of 'Reorder' anda vector giving the order of nodes in the complete tree. The ordervector must be a permutation of the vector 1:M,where M is the number of data points in the originaldata set. Specify the order from left to right for horizontal dendrograms,and from bottom to top for vertical dendrograms.

If M is greater than the number of leaf nodesin the dendrogram plot, P (by default, P is30), then you can only specify a permutation vector that does notseparate the groups of leaves that correspond to collapsed nodes.

Data Types: single | double

CheckCrossingIndicator for whether to check for crossing branches
true (default) | false

Indicator for whether to check for crossing branches in thedendrogram plot, specified as the comma-separated pair consistingof 'CheckCrossing' and either true or false.This option is only useful when you specify a value for Reorder.

When CheckCrossing has the value true, dendrogram issuesa warning if the order of the leaf nodes causes crossing branchesin the plot. If the dendrogram plot does not show a complete tree(because the number of data points in the original data set is greaterthan P), dendrogram only issuesa warning when the order of the leaf nodes causes branch to crossin the dendrogram as shown in the plot. That is, there is no warningif the order causes crossing branches in the complete tree but notin the dendrogram as shown in the plot.

Data Types: logical

ColorThresholdThreshold for unique colors
'default' | scalar value in the range (0,max(tree(:,3)))

Threshold for unique colors in the dendrogram plot, specifiedas the comma-separated pair consisting of 'ColorThreshold' andeither 'default' or a scalar value in the range (0,max(tree(:,3))).If ColorThreshold has the value T,then dendrogram assigns a unique color to eachgroup of nodes in the dendrogram whose linkage is less than T.

  • If ColorThreshold has the value 'default',then the threshold, T, is 70% of the maximum linkage, 0.7*max(tree(:,3)).

  • If you do not specify a value for ColorThreshold,or if you specify a threshold outside the range (0,max(tree(:,3))),then dendrogram uses only one color for the dendrogramplot.

OrientationOrientation of dendrogram
'top' (default) | 'bottom' | 'left' | 'right'

Orientation of the dendrogram in the figure window, specifiedas the comma-separated pair consisting of 'Orientation' andone of these values:

'top'Top to bottom
'bottom'Bottom to top
'left'Left to right
'right'Right to left

LabelsLabel for each data point
character array | string array | cell array of character vectors

Label for each data point in the original data set, specified as the comma-separated pair consisting of 'Labels' and a character array, string array or cell array of character vectors. dendrogram labels any leaves in the dendrogram plot containing a single data point with that data point’s label.

ParentParent container
Figure object | Panel object

Parent container, specified as a Figure or Panel object. For more information on these object properties, see Figure Properties and Panel Properties.

Output Arguments

collapse all

H — Handles to lines
vector

Handles to lines in the dendrogram plot, returned as a vector.

T — Leaf node numbers
column vector

Leaf node numbers for each data point in the original data set,returned as a column vector of length M, where M isthe number of data points in the original data set.

When there are fewer than P data pointsin the original data (P is 30, by default), alldata points are displayed in the dendrogram, with each node containinga single data point. In this case, T is the identitymap, T = (1:M)'.

T is useful when P isless than the total number of data points. That is, when some leafnodes in the dendrogram display correspond to multiple data points.For example, to find out which data points are contained in leaf node k ofthe dendrogram plot, use find(T==k).

outperm — Permutation of node labels
vector

Permutation of the node labels of the leaves of the dendrogramas shown in the plot, returned as a row vector. outperm givesthe order from left to right for a horizontal dendrogram, and frombottom to top for a vertical dendrogram. If there are P leavesin the dendrogram plot, outperm is a permutationof the vector 1:P.

Version History

Introduced before R2006a

See Also

cluster | clusterdata | cophenet | inconsistent | linkage | pdist | silhouette

MATLAB 命令

您点击的链接对应于以下 MATLAB 命令:

 

请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。

Dendrogram plot - MATLAB dendrogram- MathWorks 中国 (6)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

Americas

Europe

Asia Pacific

Contact your local office

Dendrogram plot - MATLAB dendrogram
- MathWorks 中国 (2024)
Top Articles
Latest Posts
Article information

Author: Patricia Veum II

Last Updated:

Views: 6454

Rating: 4.3 / 5 (44 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Patricia Veum II

Birthday: 1994-12-16

Address: 2064 Little Summit, Goldieton, MS 97651-0862

Phone: +6873952696715

Job: Principal Officer

Hobby: Rafting, Cabaret, Candle making, Jigsaw puzzles, Inline skating, Magic, Graffiti

Introduction: My name is Patricia Veum II, I am a vast, combative, smiling, famous, inexpensive, zealous, sparkling person who loves writing and wants to share my knowledge and understanding with you.