r - 使用 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)]
返回
谢谢!
解决方案
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 ,
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!
推荐阅读
- spring - 简单的基于域类的 Spring Kafka 集成
- terraform - 地形 | 模块中的变量 instance_type 应该是字符串类型,得到地图
- apache-kafka - kafka在哪里存储内部主题的偏移量?
- c# - 如何使用我的数组方法使用深度克隆?
- gatsby - 运行任何 gatsby 命令显示“-bash: gatsby: command not found”
- flutter - FlutterDriver 问题,无法通过 Key 找到 Widget
- python - 如何在另一个任务旁边运行 tkinter 的 after event?
- c++ - 是否可以在 win32 或 MFC 应用程序中从 Windows 获取“磁盘空间不足”通知?
- c# - DotNetCore3.0 WPF - error - Project file is incomplete. Expected imports are missing
- ruby-on-rails - 参数未提交