R 处理、可视化 多变量数据
1 PCA Principal Component Analysis
2 CA Correspondence Analysis
3 MCA Multiple corespondence Analysis
4 MFA Multiple Factor Analysis
5 HMFA Hierachical Multiple Factor Analysis
6. FAMD Factor Analysis of Mixed Data
如 1 PCA 部分
1 2 3 4 5 6 | library ( "FactoMineR" ) library ( "factoextra" ) data ( "decathlon2" ) # 加载数据框 glimpse (decathlon2) df<-decathlon2[1:23,1:10] df |
1 2 3 | res.pca<- PCA (df,graph = FALSE ) get_eig (res.pca) fviz_screeplot (res.pca,addlables= TRUE ,ylim= c (0,50)) |
1 2 3 4 5 | var<- get_pca_var (res.pca) # 提取变量结果 var head (var$coord) head (var$contrib) fviz_pca_var (res.pca,col.var = "black" ) |
1 | fviz_pca_var (res.pca,col.var = "contrib" ,gradient.cols= c ( "#00AFBB" , "#E7B800" , "#FC4E07" ),repel = TRUE ) # 按变量的contributions 给他们上色 |
1 2 3 | # 变量在不同主成分水平的贡献 fviz_contrib (res.pca,choice = "var" ,axes=1,top = 10) fviz_contrib (res.pca,choice= "var" ,axes=2,top=10) |
1 2 3 4 5 | # 提取、可视化个体的pca结果 ind<- get_pca_ind (res.pca) ind head (ind$coord) fviz_pca_ind (res.pca,col.ind = "cos2" ,gradient.cols= c ( "#00AFBB" , "#E7B800" , "#FC4E07" ),repel = TRUE ) |
1 | fviz_pca_biplot (res.pca,repel = TRUE ) ## Biplot of individuals and variables |
1 2 3 | # 按组别给个体上色 iris.pca<- PCA (iris[,-5],graph= FALSE ) fviz_pca_ind (iris.pca,lable= "none" ,habillage = iris$Species,palette = c ( "#00AFBB" , "#E7B800" , "#FC4E07" ),addEllipses = TRUE ) |
参考 https://rpkgs.datanovia.com/factoextra/
本文来自博客园,作者:BioinformaticsMaster,转载请注明原文链接:https://www.cnblogs.com/koujiaodahan/p/15867624.html
分类:
统计R
posted on 2022-02-07 13:39 BioinformaticsMaster 阅读(202) 评论(0) 编辑 收藏 举报
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 【.NET】调用本地 Deepseek 模型
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库