R中利用cluster简单的绘制常见聚类离散图
# 引入cluster库(clara、fanny)library(cluster)# 聚类散点图绘制# 引入factoextra,cluster库(fviz_cluster)library(ggplot2)library(factoextra)# 确定簇心个数cluster_num <- 3# 读取数据data <- read.csv("data.csv",header = T)# 调用kmeans算法km <- kmeans(data,cluster_num)# 调用Clara算法cl <- clara(data,cluster_num)# 调用模糊C-Means聚类算法fan <- fanny(data,cluster_num) # 绘图#fviz_cluster(km, data, ellipse.type = "norm")fviz_cluster(fan, data)