如何根据一个因素为PCA结果着色?

时间:2019-01-31 10:09:43

标签: r pca

我正在使用多个数值变量(这里称为Env_)的数据集,这些数据集已经创建了PCA。所有这些变量代表环境因素。我还具有许多与环境因素相关联的代表生物多样性值的分类变量(以下称为Biodiv_)。我已经将生物多样性价值变成了一个具有50个水平的因子。

我想基于环境因素创建PCA,我已经完成了。接下来,我将根据我的生物多样性变量为各个数据点着色,以便直观地检查在哪里发现多样性的高低水平。基本上,我想要一个类似于the plot under segment 2 for Visualize PCA results的图,但是我不想根据cos2进行着色,而是根据我的生物多样性命运Biodiv_为我的点着色。

我目前正在使用ade4和FactoMineR软件包来创建和可视化我的PCA。我遵循了FactoMineR的总体准则。我也尝试过使用fviz_pca,但运气不好。

PCA1 <- PCA(complete[ ,1:9], 
        scale.unit = TRUE, graph = TRUE) 
##Provides a PCA plot with my 9 environmental variables

PCA2 <- PCA(complete, scale.unit = TRUE, 
        ncp = 5, quali.sup = c(10), graph = TRUE) 
##My attempt at adding the biodiversity factor to the plot. No change appear at my plot compared to the line above

plot.PCA(PCA2, axes = c(1,2), choix = "ind", habillage = 50) 
##I wish to color the points accoring to the biodiversity factor with 50 levels. 

发生以下错误:

Error in plot.PCA(complete_2PCA, axes = c(1, 2), choix = "ind", habillage = 50) : 
The variable 50 is not qualitative    

我的数据示例:

Env_1 Env_2   Env_3    Env_4   ... Env_9     Biodiv_10
14    78.9675 61.8300  5.4725  ... 4.947368  0.00
12    43.6950 14.8475  5.3775  ... 5.714286  0.12
15    56.1875 31.2800  6.1100  ... 5.200000  0.15
13    84.0100 68.7825  5.8500  ... 5.625000  0.88
24    63.4125 26.5525  5.5675  ... 5.363636  0.05
16    51.3175 19.5025  5.6950  ... 5.555556  0.76

我希望结果图根据我的Biodiv_因素着色,但这不会发生。

0 个答案:

没有答案