As per Ram, you can easily do it with the rotation matrix from prcomp. For example:
pca <- prcomp(x)
# indices of top 500 genes on PC1 by absolute value
values1 <- order(abs(pca$rotation[,1]), decreasing=TRUE)[1:500]
# indices of top 500 genes on PC2 by absolute value
values2 <- order(abs(pca$rotation[,2]), decreasing=TRUE)[1:500]
et cetera
Note that DESeq2's plotPCA() function removes genes based on low variance prior to performing PCA. So, which do you want:
remove genes based on low variance prior to performing PCA (via
prcomp())?
identify the top 500 genes contributing to variance in your dataset
along PC3 and PC4 after you have performed PCA on your entire
dataset (as per my code, above)?
This is very helpful, thanks! I'm really new to prcomp and am having trouble figuring out what the x represents? Do you perhaps have a longer stretch of code I could look at? Thanks!
In this case, x represents your input data-matrix. By the way, my PCAtools package was accepted to Bioconductor since this post, and will be officially released at the end of this month. Details here: https://github.com/kevinblighe/PCAtools
Hello! I'm creating PCA plots with a whole transcriptome dataset, which includes 26,828 'genes', to assess similarity between three groups (E, M and L). I'm …
IIRC prcomp gives you a rotation matrix, from which you can get genes that contribute the most to PC3 and PC4. You could then use that subset to plot.
pcaExplorer is a cool package which can do it.
You can find more information here: pcaExplorer
As per Ram, you can easily do it with the rotation matrix from prcomp. For example:
Note that DESeq2's
plotPCA()function removes genes based on low variance prior to performing PCA. So, which do you want:prcomp())?This is very helpful, thanks! I'm really new to prcomp and am having trouble figuring out what the x represents? Do you perhaps have a longer stretch of code I could look at? Thanks!
In this case,
xrepresents your input data-matrix. By the way, my PCAtools package was accepted to Bioconductor since this post, and will be officially released at the end of this month. Details here: https://github.com/kevinblighe/PCAtoolsIt is awesome!!! Thank you!