如何在R中突出显示特定变量或个人的特定变量或个人
我目前正在研究我执行PCA的大型数据集(用物种X样品计数数据)。我得到的是巨大的点云,我想为一个给定的物种上色以显示它位于云中的位置(物种是我在这里的变量)。以下是:
我使用factoextra的软件包,并将变量可视化FVIZ_PCA_VAR。有没有办法选择一种特定物种并以与其他物种不同的颜色显示?
感谢您的帮助
I am currently working on a large dataset (count data with species x samples) from which I performed a PCA. What I get is a massive cloud of points, and I would like to color one given species to show where it is located in this cloud (species are my variables here). Here is what it looks like :
I use the package factoextra, and visualize the variables with fviz_pca_var. Is there a way to select one particular species and display it with a color different than the others ?
Thank you for your help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果只是您要着色的一个点,也许是:
在2022-07-08创建的a href =“ https://reprex.tidyverse.org” rel =“ nofollow noreferrer”> reprex软件包 (v2.0.1)
您还可以使用
由
If it's just a single point you want to color, perhaps:
Created on 2022-07-08 by the reprex package (v2.0.1)
You can also label specific points (i.e. just the point of interest) using this approach, e.g.
Created on 2022-07-08 by the reprex package (v2.0.1)
我不会标记每个数据点。只需使用传说,并突出显示您的物种,例如。红色和所有其他物种绿色。
您没有提供示例数据,因此我为您提供了其他示例数据的解决方案。请参阅下面的代码。使用FactoExtra(和FactoMiner)为所有数值列制作PCA。然后在绘制PCA的两个维度时,添加一个因子变量作为物种的荧光笔。只需使用简单的iFelse列制作一个新的因子VAR即可将您的物种与其他物种分开。使用此因子列在FVIZ_PCA_IND图中突出显示。请参阅下面的代码:
I would not label every data point. Just use a legend and highlight your species with, eg. red color, and all other species green.
You did not provide example data, so I give you a solution with other sample data. See the code below. Using factoextra (and factominer) make your pca for all numerical columns. Then add a factor variable as a highlighter of your species when plotting the 2 dimensions of the PCA. Just make a new factor var with a simple ifelse column to separate your species from the rest. Use this factor column for highlighting in the fviz_pca_ind plot. See code below for an example: