Hierarchical clustering remains one of the most widely used unsupervised learning techniques in analytics, machine learning, and applied data science. Despite the rise of large-scale and deep-learning–based clustering approaches, hierarchical methods continue to be preferred for interpretability, explainability, and exploratory data analysis, especially in business analytics, social sciences, bioinformatics, and market segmentation.This updated guide revisits hierarchical clustering using modern R workflows and industry best practices, while preserving the original intent: building a strong conceptual foundation and implementing clustering step by step in R.
Clustering is a technique used to group similar observations into clusters while keeping dissimilar observations separate. Hierarchical clustering differs from other clustering approaches (such as k-means) because it builds a tree-based structure (hierarchy) rather than forcing the data into a fixed number of clusters upfront.A simple analogy is a library system:
This naturally forms a hierarchy, which is exactly how hierarchical clustering organizes data.Hierarchical clustering produces a dendrogram, a tree-like diagram that visually represents how clusters are merged or split at different levels of similarity.
Hierarchical clustering can be performed in two fundamental ways:
In the divisive approach, all observations start in a single cluster. The algorithm then repeatedly splits clusters into smaller ones until each observation forms its own cluster.This method is commonly known as DIANA (Divisive Analysis).Key characteristics:
The agglomerative approach is the most widely used hierarchical method in real-world analytics. It begins with each observation as its own cluster and then iteratively merges the most similar clusters.This method is also known as:
Why it dominates industry usage:
In practice:
Divisive methods are useful for high-level segmentation, while agglomerative methods excel at discovering fine-grained patterns.
For the rest of this article, we focus on Agglomerative Hierarchical Clustering, which accounts for the majority of production and research use cases.
The classical hierarchical clustering procedure, formalized by Johnson, follows these steps:
This process results in a nested hierarchy, which can later be cut at any level to obtain a desired number of clusters.
The effectiveness of hierarchical clustering depends heavily on how distances between clusters are defined. The most commonly used linkage methods are:
Current best practice:
Ward’s method is often the default choice for numeric data when interpretability and cluster compactness matter.
Before clustering, data preparation is critical:
We’ll use the Freedman dataset from the car package, which contains socio-economic indicators for U.S. metropolitan areas.
data <- car::Freedman data <- na.omit(data) data <- scale(data)
Scaling ensures that no variable dominates the clustering process due to unit differences—a standard requirement in modern analytics pipelines.
R provides robust, well-maintained tools for hierarchical clustering:
hclust() from the stats packageagnes() and diana() from the cluster packagehclustd <- dist(data, method = "euclidean") hc <- hclust(d, method = "complete") plot(hc, cex = 0.6, hang = -1)
agnesThe agnes() function provides an agglomerative coefficient, which quantifies clustering strength (values closer to 1 indicate stronger structure).
hc_agnes <- agnes(data, method = "complete") hc_agnes$ac
A modern workflow involves evaluating multiple linkage strategies before choosing one.
methods <- c("average", "single", "complete", "ward")
ac <- sapply(methods, function(m) agnes(data, method = m)$ac)
acIn most real-world datasets, Ward’s method typically yields the strongest clustering structure.
dianaAlthough less common, divisive clustering can still be valuable for high-level exploration.
hc_div <- diana(data) hc_div$dc pltree(hc_div, cex = 0.6, hang = -1)
Once the dendrogram is built, clusters can be extracted using cutree().
clusters <- cutree(hc_div, k = 5)
For visualization, the factoextra package offers modern plotting utilities:
fviz_cluster(list(data = data, cluster = clusters))
The dendextend package enables advanced dendrogram customization and comparison.
library(dendextend) hc_single <- as.dendrogram(agnes(data, method = "single")) hc_complete <- as.dendrogram(agnes(data, method = "complete")) tanglegram(hc_single, hc_complete)
Tanglegrams are particularly useful for method comparison, model validation, and research reporting.
Hierarchical clustering remains a cornerstone of exploratory data analysis in 2026. While modern datasets are growing larger and more complex, hierarchical methods continue to deliver unmatched interpretability and flexibility.In this article, we:
While we assumed the number of clusters (k) was known, real-world projects often require experimentation and domain expertise. Use business context, validation metrics, and visualization together—no single heuristic works best for all datasets.Hierarchical clustering is not just a technique; it’s a thinking framework for understanding structure in data.
Our mission is “to enable businesses unlock value in data.” We do many activities to achieve that—helping you solve tough problems is just one of them. For over 20 years, we’ve partnered with more than 100 clients — from Fortune 500 companies to mid-sized firms — to solve complex data analytics challenges. Our services include Snowflake Consultants and Power bi implementation services— turning raw data into strategic insight.