根据PCA中的名称对行进行子设置

时间:2019-04-24 19:32:53

标签: r

我想通过PCA上的站点名称对数据进行子集化。

我有大约200行的矩阵数据。他们列出了站点名称,年份和环境数据。我不得不转换我的数据。然后,我对所有数据(总共20个站点)运行了PCA。对于项目范围,我只想在双线图上显示某些站点,而要使用整个数据集的箭头长度。因为我混合了-和+号,所以subset命令不起作用。我正在使用两个不同的绘图命令:cleanplot和autoplot。

创建var.subset不适用于-/ +。 我也尝试了select.ind的fviz_pca_ind命令,但也没有用。

我对R还是比较陌生,并不精通所有软件包,并且已经搜索了几个小时。

## a small/abridged sample of the type of data I am working with. 

view(env)

site     coral_cover      soft_coral    algae
A   -1.299642738    -0.899981100    0.31297676
A   -0.543243466    -0.899981100    -0.37866568
A   -1.369679707    -0.899981100    -0.37866568
B   -1.243613162    -0.899981100    -0.24033719
B   -1.411701889    -0.899981100    -0.37866568
B   0.269185382 0.232783249 -0.37866568
B   0.759444169 -0.220322491    -0.30950144
C   1.473821260 -0.107046056    -0.37866568
C   -0.669310011    0.346059684 -0.30950144
C   0.241170594 1.592100468 -0.37866568
C   1.781983926 -0.673428230    -0.37866568
D   2.324770441 -0.050407838    1.35044042
D   0.507311079 -0.220322491    0.10548403
D   -1.327657526    0.346059684 -0.37866568
D   -0.669310011    0.912441858 -0.37866568
E   0.871503321 -0.333598926    -0.37866568
E   0.643883169 -0.475194469    -0.20575507
E   0.003044897 -0.899981100    0.17464827

# PCA on the environmental data
env.pca <- rda(env) 


##Plot
dev.new(width = 8,
        height = 6,
        title = "PCA biplots - env - autoplot", 
        noRStudioGD = TRUE
)
par(mfrow = c(1, 1))
autoplot(prcomp(env), 
         data= env.all, 
         colour= "reserve_status",  
         shape= "site",
         loadings= TRUE, 
         loadings.colour = 'black',
         loadings.label=TRUE, 
         loadings.label.colour = 'black',
         mar.percent = 0.5
) 

##This command will show all 5 sites, but what if I only wanted to display "A", "C" and "E"

This is the plot with everything on it

这基本上是我想要的,但是能够选择我想要的站点。由于代码错误,导致出现此图。 What I want-ish

0 个答案:

没有答案
相关问题