Pulling out Outlier Data from PCA in R

78 Views Asked by At

My plot I created a PCA chart on r using the code below, but I want to pull the data from the outliers (anything outside my circle), out so that I can compare their data. If anyone could help out with how I would code to pull that info out it would be helpful!

I used this code and have the chart attached, so everything looks right here I just dont know how to pull out only the outlier data.

library(vcfR)
library(poppr)
library(ape)
library(RColorBrewer)

#load in file and validate
rubi.VCF <- read.vcfR("//Users/myname/Downloads/not.vcf")
rubi.VCF

gl.rubi <- vcfR2genlight(rubi.VCF)
ploidy(gl.rubi) <- 2
gl.rubi

rubi.pca <- glPca(gl.rubi, nf = 3)
barplot(100*rubi.pca$eig/sum(rubi.pca$eig), col = heat.colors(50), main="PCA Eigenvalues")
title(ylab="Percent of variance\nexplained", line = 2)
title(xlab="Eigenvalues", line = 1)

rubi.pca.scores <- as.data.frame(rubi.pca$scores)
rubi.pca.scores$pop <- pop(gl.rubi)

library(ggplot2)
set.seed(9)
p <- ggplot(rubi.pca.scores, aes(x=PC1, y=PC2) )
p <- p + geom_point(size=2)
p <- p + stat_ellipse(level = 0.95, size = 1)
#p <- p + scale_color_manual(values = cols) 
p <- p + geom_hline(yintercept = 0) 
p <- p + geom_vline(xintercept = 0) 
p <- p + theme_bw()

p
0

There are 0 best solutions below