聚类绘图
To install factoextra, type this: install.packages(“factoextra”).
We’ll use the USArrest data set and we start by standardizing the data:
df <- scale(USArrests)
# Compute hierarchical k-means clustering library(factoextra) res.hk <-hkmeans(df, 4) # Elements returned by hkmeans() names(res.hk)
## [1] "cluster" "centers" "totss" "withinss" ## [5] "tot.withinss" "betweenss" "size" "iter" ## [9] "ifault" "data" "hclust"
To print all the results, type this:
# Print the results res.hk
# Visualize the tree fviz_dend(res.hk, cex = 0.6, palette = "jco", rect = TRUE, rect_border = "jco", rect_fill = TRUE)

# Visualize the hkmeans final clusters fviz_cluster(res.hk, palette = "jco", repel = TRUE, ggtheme = theme_classic())

Summary
We described hybrid hierarchical k-means clustering for improving k-means results.
请关注“恒诺新知”微信公众号,感谢“R语言“,”数据那些事儿“,”老俊俊的生信笔记“,”冷🈚️思“,“珞珈R”,“生信星球”的支持!