聚类分析-R语言

1,原始数据,是矩阵,有行头和列名:


data

2,amap包的聚类分析:

library(amap)
clu <- hclusterpar(matx)
plot(clu,sub="",hang = -1,xlab = NA,ylab = NA,main = NA)
cluster

用法:
hcluster(x, method = "euclidean", diag = FALSE, upper = FALSE,
link = "complete", members = NULL, nbproc = 2,
doubleprecision = TRUE)

3,cluster包

library(cluster)
agnx <- agnes(matx,method = "complete")
pltree(agnx)

agnes(x, diss = inherits(x, "dist"), metric = "euclidean",
stand = FALSE, method = "average", par.method,
keep.diss = n < 100, keep.data = !diss, trace.lev = 0)
默认方法不一样,这里改为complete

cluster2

转化为横着排放的格式:

dagn  <- as.dendrogram(as.hclust(agnx))
plot(dagn, horiz = TRUE, center = TRUE,
     nodePar = list(lab.cex = 0.6, lab.col = "forest green", pch = NA),
     main = deparse(agn$call))
图片.png

你可能感兴趣的:(聚类分析-R语言)