hierfly | R Documentation |
Supplements a data set with information needed to draw a dendrogram. Intermediate cluster nodes are added as needed, and positioned at the centroid of the combined clusters. Note that categorical variables need to be factors.
hierfly(data, h = NULL, metric = "euclidean", method = "ward.D2", scale = TRUE)
data |
data set |
h |
an hclust object |
metric |
distance metric to use, see |
method |
cluster distance measure to use, see |
scale |
logical value whether to scale data or not, default TRUE |
list with data and edges and segments
data(clusters)
cl_dist <- dist(clusters[,1:5])
cl_hw <- hclust(cl_dist, method="ward.D2")
require(ggdendro)
ggdendrogram(cl_hw, type = "triangle", labels = FALSE)
clusters$clw <- factor(cutree(cl_hw, 3))
cl_hfly <- hierfly(clusters, cl_hw, scale=FALSE)
if (interactive()) {
require(tourr)
glyphs <- c(16, 46)
pch <- glyphs[cl_hfly$data$node+1]
require(colorspace)
clrs <- heat_hcl(length(unique(cl_hfly$data$clw)))
pcol <- clrs[cl_hfly$data$clw]
ecol <- clrs[cl_hfly$data$clw[cl_hfly$edges[,1]]]
animate_xy(cl_hfly$data[,1:5], edges=cl_hfly$edges,
col=pcol, pch=pch, edges.col=ecol,
axes="bottomleft")
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.