R function from {stats} package - hierarchical cluster analysis on a set of dissimilarities and methods for analyzing it.
Questions tagged [hclust]
176 questions
30
votes
2 answers
Clustering list for hclust function
Using plot(hclust(dist(x))) method, I was able to draw a cluster tree map. It works. Yet I would like to get a list of all clusters, not a tree diagram, because I have huge amount of data (like 150K nodes) and the plot gets messy.
In other words,…

dave
- 299
- 1
- 3
- 11
23
votes
2 answers
horizontal dendrogram in R with labels
I am trying to draw a dendrogram from the hclust function output. I hope the dendrogram is horizontally arranged instead of the default, which can be obtain by (for example)
require(graphics)
hc <- hclust(dist(USArrests), "ave")
plot(hc)
I tried to…

alittleboy
- 10,616
- 23
- 67
- 107
20
votes
1 answer
How to use 'hclust' as function call in R
I tried to construct the clustering method as function the following ways:
mydata <- mtcars
# Here I construct hclust as a function
hclustfunc <- function(x) hclust(as.matrix(x),method="complete")
# Define distance metric
distfunc <- function(x)…

neversaint
- 60,904
- 137
- 310
- 477
18
votes
1 answer
setting distance matrix and clustering methods in heatmap.2
heatmap.2 defaults to dist for calculating the distance matrix and hclust for clustering.
Does anyone now how I can set dist to use the euclidean method and hclust to use the centroid method?
I provided a compilable code sample bellow.
I tried:…

jonas87
- 672
- 2
- 8
- 22
13
votes
3 answers
Removing x-axis label from dendrogram in r
I use xlab="" to suppress the x-label but still get a 'sub-x-label' in my dendrogram. How can I remove this and remove any extra space under the dendrogram?
require(graphics)
hc <- hclust(dist(USArrests), "ave")
plot(hc,xlab="")

Elizabeth
- 6,391
- 17
- 62
- 90
12
votes
1 answer
Change label size of Cluster Dendrogram in R 3.01
Has anybody found a workaround to the apparent bug in R 3 which prohibits changing the label size on a Cluster Dendrogram?
The following code used to work fine before updating R to 3.01 (prior version was 2.15 I think):
plot(hclust, labels = data[,…

Jonathan Mulligan
- 352
- 2
- 3
- 10
8
votes
1 answer
How do I color edges or draw rects correctly in an R dendrogram?
I generated this dendrogram using R's hclust(), as.dendrogram() and plot.dendrogram() functions.
I used the dendrapply() function and a local function to color leaves, which is working fine.
I have results from a statistical test that indicate if a…

Alex Reynolds
- 95,983
- 54
- 240
- 345
8
votes
3 answers
Tree cut and Rectangles around clusters for a horizontal dendrogram in R
I am trying to plot the results of a hierarchical clustering in R as a dendrogram, with rectangles identifying clusters.
The following code does the trick for a vertical dendrogram, but for a horizontal dendrogram, (horiz=TRUE), the rectangles are…

Crops
- 5,024
- 5
- 38
- 65
5
votes
2 answers
Merging multiple hclust objects (or dendrograms)
Is there an easy way to merge multiple hclust objects (or dendrograms) at the root?
I've made the example as complete as possible to illustrate my problem.
Let's say I'd like to cluster USArrests by region and then unite all the hclust objects to…

csgroen
- 2,511
- 11
- 28
5
votes
1 answer
hclust() in R on large datasets
I am trying implement hierarchical clustering in R : hclust() ; this requires a distance matrix created by dist() but my dataset has around a million rows, and even EC2 instances run out of RAM. Is there a workaround?

Mayank
- 51
- 1
- 3
5
votes
1 answer
Extract distances from hclust (hierarchical clustering) object
I would like to calculate how good the fit of my cluster analysis solution for the actual distance scores is. To do that, I need to extract the distance between the stimuli I am clustering. I know that when looking at the dendrogram I can extract…

Esther
- 441
- 2
- 15
5
votes
1 answer
Usning cutree with phylo object (unrooted tree) in R
I would like to use the cutree() function to cluster a phylogenetic tree into a specified number of clades. However, the phylo object (an unrooted phylogenetic tree) is not unltrametric and thus returns an error when using as.hclust.phylo(). The…

ONeillMB1
- 343
- 6
- 19
5
votes
3 answers
R cut dendrogram into groups with minimum size
Is there an easy way to calculate lowest value of h in cut that produces groupings of a given minimum size?
In this example, if I wanted clusters with at least ten members each, I should go with h = 3.80:
# using iris data simply for reproducible…

C8H10N4O2
- 18,312
- 8
- 98
- 134
5
votes
2 answers
Plot horizontal dendrogram with hanging leaves? (R)
I would like to create a dendrogram plot with horizontal labels, but having the leaves hang according to their height, instead of just drop to the edge of the plot.
Example:
par(mfrow = c(1,2))
hc <- hclust(dist(USArrests), "ave")
plot(hc) # a plot…

Tal Galili
- 24,605
- 44
- 129
- 187
5
votes
1 answer
Error with multiscale hierarchical clustering in R
I'm doing hierarchical clustering with an R package called pvclust, which builds on hclust by incorporating bootstrapping to calculate significance levels for the clusters obtained.
Consider the following data set with 3 dimensions and 10…

oisyutat
- 197
- 2
- 7