pca_plot | R Documentation |
Plots results of a PCA, e.g., scatterplot, screeplot, and cumulative
explained variance plots. Takes prcomp
object as the main input.
pca_plot(
pcaObj,
type = "scatter",
axisIndex = NULL,
pops = NULL,
plotColours = NULL,
plotLook = "ggplot",
legendPos = "top"
)
pcaObj |
Prcomp object: A PCA of genotype data fitted using the
|
type |
Character: What type of plot to make: a scatterplot ( |
axisIndex |
Integer: The PC axes to plot. If |
pops |
Character: A vector of population IDs, should match the
rows in |
plotColours |
Character: A vector of colours to use for plotting,
but is an optional argument. Default = |
plotLook |
Character: The look of the plot. Default = |
legendPos |
Character: Where should the legend be positioned? Default is
|
Returns a ggplot object.
library(genomalicious)
data(data_Genos)
# Conduct the PCA with Patterson et al.'s (2006) normalisation, and
# population specified
PCA <- pca_genos(dat=data_Genos, scaling='patterson', popCol='POP')
# Plot the PCA
pca_plot(PCA)
# Plot axies 2 and 3, custom colours, and a classic look.
pca_plot(
PCA,
axisIndex=c(2,3),
plotColours=c(Pop1='gray30', Pop2='royalblue', Pop3='palevioletred3', Pop4='plum2'),
plotLook='classic'
)
# Explained variance
pca_plot(PCA, type='scree')
# Cumulative variance for the first 10 axes with custom colour
pca_plot(PCA, type='cumvar', axisIndex=1:10, plotColours='royalblue')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.