library(reshape2)
library(ggplot2)
# Sample data
dat = iris[, 1:4]
# Clusters
d = dist(dat)
h = hclust(d)
# Set groups
s = cutree(h, k = 3)
plot(h)
rect.hclust(h, k = 3)
# Distribution of variables in each group
dat$cluster = s
dat = melt(dat, id.vars = "cluster")
dat$cluster = factor(dat$cluster)
ggplot(dat, aes(x = cluster, y = value, fill = cluster)) +
geom_boxplot() +
facet_wrap(~ variable, scales = "free_y") +
theme_bw()