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)