pca2DT | R Documentation |
prcomp
object to a long-format data.table
Convert a prcomp
object to a long-format data.table
pca2DT(pcaObj, pops = NULL, subAxes = NULL)
pcaObj |
Prcomp: An object produced by |
pops |
Character: An optional vector of population IDs. Default is |
subAxes |
Integer: An optional vector of values to subset the PC axes. Default is NULL. |
Returns a long-format data.table with columns $POP
, the
population IDs (if data available), $SAMPLE
, the sample IDs,
$PC[x]
, the individual PC axes, with [x]
denoting the axis number.
library(genomalicious)
data(data_Genos)
# With populations
PCA.pops <- pca_genos(data_Genos, popCol='POP')
pca2DT(PCA.pops) %>% print
# Without populations and all axes (default)
PCA.nopops <- pca_genos(data_Genos)
pca2DT(PCA.nopops) %>% print
# Manual populations, with just the first three axes
pops <- rownames(PCA.nopops$x) %>%
sub('Ind', '', .) %>%
sub('_.*', '', .)
pops
pca2DT(PCA.nopops, pops=pops, subAxes=1:3) %>% print
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.