# Demonstration of converting a clusterpath into a dendrogram, first generate
# data
set.seed(6)
X = matrix(rnorm(14), ncol = 2)
y = rep(1, nrow(X))
# Get sparse distances in dictionary of keys format with k = 3
W = sparse_weights(X, 3, 4.0)
# Sequence for lambda
lambdas = seq(0, 45, 0.02)
# Compute results
res = convex_clusterpath(X, W, lambdas)
# Generate hclust object
hcl = as.hclust(res)
hcl$height = sqrt(hcl$height)
# Plot clusterpath and dendrogram
oldpar = par(mfrow=c(1, 2))
plot(res, y, label = c(1:7))
plot(hcl, ylab = expression(sqrt(lambda)), xlab = NA, sub = NA, main = NA,
hang = -1)
par(oldpar)
Run the code above in your browser using DataLab