How to add colors to the PCA made using SNPRelate
Entering edit mode
zen • 0
Last seen 2.7 years ago

Hi All, I have made a PCA plot from SNP data using SNPRelate with following code:


vcf.fn <- "input.vcf"
snpgdsVCF2GDS(vcf.fn, "test.gds", method="biallelic.only")
genofile <- snpgdsOpen("test.gds")
pop_code <- read.gdsn(index.gdsn(genofile, "genotype"))
snpset <- snpgdsLDpruning(genofile, autosome.only=FALSE, ld.threshold=0.1) <- unlist(snpset)

pca <- snpgdsPCA(genofile, autosome.only=FALSE,, num.thread=2)
pc.percent <- pca$varprop*100
head(round(pc.percent, 2))
tab <- = pca$,
                  EV1 = pca$eigenvect[,1],    
                  EV2 = pca$eigenvect[,2],    
                  stringsAsFactors = FALSE)
plot(tab$EV2, tab$EV1, xlab="eigenvector 2", ylab="eigenvector 1")

I want to add colors to the plot based on pre-defined groups in the population. However, my input file does not have that information. I have a separate file for the group information with two columns in dataset named "" and "group". I have seen some posts for adding color to the PCA plot using SNPRelate if the input file used to generate PCA plot has this information. In my case, I have a separate file and I could not find a way to make my file work for SNPRelate to add colors to plot. Is there any different way of doing the same thing with some other resource. Thank you for the help!

snprelate • 753 views
Entering edit mode
Last seen 16 hours ago
United States

You aren't using anything in SNPRelate to do the plotting, but instead are calling the base plot function. Which is fine! There is a help page for that function that tells you pretty much everything you need to know, including how to change the colors on the plotting symbols, as well as how to change the plotting symbols themselves.

If, after reading the help page, you still have questions about how to use plot, you could ask questions on, or maybe or Or better yet, use a well crafted Google search. Knowing how to search for answers is a very good skill to have, particularly if you plan on doing much at all with R.


Login before adding your answer.

Traffic: 552 users visited in the last hour
Help About
Access RSS

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6