首页 > 解决方案 > 使用 fviz_pca 在 Biplot 上添加圆圈以将具有第二个因素的个人分组

问题描述

谢谢你读我。我是 R 新手,所以我迷路了:如何在使用 fviz_pca 制作的双图上添加由第二个因素定义的组圆?我有这张,并想应用 PCA 来获得一个双标图,其中个人按“UsoReg”(土地使用)因子分类(着色)(直到这里都很好),但我也想添加圆圈(或一些椭圆形)用第二个因素包围(组)个人,根据“Estacion”(一年中的季节)列命名,但我不知道该怎么做。那么,如何在使用 FactoMiner 制作的 Biplot 上添加圆圈以通过第二个因素包围(分组)个人?(第一个因素是“UsoReg”,并通过fill.ind功能,第二个因素是“Estacion”,我不知道如何根据他们的“Estacion”类绘制圆圈来分组/包围个人)。我想在 3 个不同的土地利用类别(CoigueIX、MixtaIX、AgricolaIX)上可视化 3 个不同的季节(Estacion:Otono、Invierno、Primavera),谢谢。我使用以下代码:

PCA_PQ<-function(X){
pca.m<-prcomp(X, scale=TRUE)
contrib_rpca.m<-pca.m$rotation
c_pca.m<-pca.m$center
s_pca.m<-pca.m$scale}
scale(X,center=c_pca.m,scale=s_pca.m)
ev_pca.m<-get_eig(pca.m)
Biplot_pca.m<-fviz_pca_biplot(pca.m,
geom.ind="point",
fill.ind=IX_comp$UsoReg,
col.ind="cos2",
pointshape=21,pointsize=2,
mean.point=FALSE,
alpha.var="contrib",col.var="contrib",
gradient.cols=c("#00AFBB","#E7B800","#FC4E07"),
labelsize=5,
repel=TRUE,
xlab="PC 1",
ylab="PC 2")+
labs(fill="Uso", color="Contrib",alpha="Contrib")+
ggpubr::fill_palette(c("green","yellow","red"))+
theme(text=element_text(size=9),
axis.title=element_text(size=15),
axis.text=element_text(size=12))
plot(Biplot_pca.m)}

PCA_PQ(IX_comp[,c(4,6:14)]

返回

双标图1

谢谢!

标签: rpcabiplotfactominer

解决方案


After looking and experimenting with different options i found that adding

ggplot2::stat_ellipse(aes(group=IX_comp$Estacion))

to the script above, i get what i was looking for biplot,

but now i need to change some parameters of the ovals printed in the plot, and add their labels to the legend.

I want to make ovals borders thinner, set different colors for them according to their factor classification (in IX_comp$Estacion) and add their names and colors to the legend.

Thanks for your help and attention!


推荐阅读