如何在r的PCA图中找到数据点? [英] How can I find the data point in my PCA plot in r?

查看:52
本文介绍了如何在r的PCA图中找到数据点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ggplot2中制作了该PCA图.有没有办法找到我的哪个数据产生了带有红色箭头的数据点?我想让R告诉我该数据点关联了哪些物种(我与每个点都有关联的名称,代表一个物种的PC得分)

I made this PCA plot in ggplot2. Is there a way to find which of my data produced the data point with the red arrow? I'd like R to tell me what species is associated with this data point (I have names associated with each dot, which represents a species PC score)

代码:

df_out <- as.data.frame(PPCA.scores)
theme <-
  theme(
    panel.background = element_blank(),
    panel.border = element_rect(fill = NA),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    strip.background = element_blank(),
    axis.text.x = element_text(colour = "black"),
    axis.text.y = element_text(colour = "black"),
    axis.ticks = element_line(colour = "black"),
    plot.margin = unit(c(1, 1, 1, 1), "line")
  )
percentage <- round(PPCA$Eval / sum(PPCA$Eval) * 100, 2)
percentage <- diag(as.matrix(percentage))
percentage <- paste0(names(percentage), " (", percentage, "%)")

p<-ggplot(df_out,aes(x=PC1,y=PC2)) 
p<-p+geom_point(size=3) + theme + xlab(percentage[1]) + ylab(percentage[2])
p  

推荐答案

factoextra 提供了一种通过标记单个数据点来执行PCA的方法

The package factoextra provides a way to carry out PCA with labelling individual data points

set.seed(123)

# pca object
res.pca <- prcomp(iris[, -5],  scale = TRUE)

# plot
factoextra::fviz_pca_biplot(res.pca, repel = TRUE)

reprex软件包(v0.2.1)创建于2018-11-10

有关详细文档,请参阅-

For more detailed documentation, see- http://www.sthda.com/english/articles/31-principal-component-methods-in-r-practical-guide/112-pca-principal-component-analysis-essentials/

这篇关于如何在r的PCA图中找到数据点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆