如何在R中的fviz_pca_biplot中绘制聚类?

时间:2019-06-06 13:39:24

标签: r ggplot2 pca prcomp

我想在我的fviz_pca_biplot中绘制聚类结果

我确实使用库Factorextra创建了具有eclust函数的聚类分析和PCA(prcomp),我正在用fviz_pca_biplot绘制pca,但是我想将聚类图添加到我的fviz_pca_biplot图中,这可能吗? / p>

library(devtools)
library(ggbiplot)
library(readxl)

vv.poll6<-read.csv("vv_poll.csv")
vv.veg6<-read.csv("vv_veg_free100.csv")
vv.land = read.csv("vv_landscape.csv")

vv.poll6.p<-vv.poll6[,-1]/rowSums(vv.poll6[,-1])
vv.poll6.p2 = (sqrt(vv.poll6.p))
vv.veg6.p<-vv.veg6[ ,-c(1,2)]/rowSums(vv.veg6[ ,-c(1,2)])
vv.veg6.p2 = (sqrt(vv.veg6.p))
vv.poll6.pca = prcomp(vv.poll6.p2, center = TRUE, scale. = FALSE)

library("factoextra")

fviz_pca_biplot(vv.poll6.pca, col.var = "black", col.ind = vv.land$Landscape, palette = "Dark2", label = "all", repel = TRUE, legend.title = "Landscape", title = "PCA Vila Velha - Pollen")

# Cluster - I want to add this results to the previous plot 

veg.norm6<-decostand(sqrt(vv.veg6.p), "normalize")
clust.vv = eclust(veg.norm6, FUNcluster = c("hclust"), hc_metric = "euclidean", hc_method = "ward.D2")
res.hc6.vv <- eclust(veg.norm6, "hclust", hc_metric = "euclidean", hc_method = "ward.D2", k = 2) # compute hclust
fviz_dend(res.hc6.vv, rect = TRUE) # dendrogam
fviz_cluster(res.hc6.vv)

0 个答案:

没有答案