# micro_pca: Calculate and plot principle components In tidyMicro: A Pipeline for Microbiome Analysis and Visualization

## Description

Principle components are calculated on the centerted log ratio tranformation of the OTU table using the `prcomp` function from the `stats` package. Scaling the OTU table to a unit variance is the default option, and recommended, but this can be changed using scaled = F.

## Usage

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14``` ```micro_pca( micro_set, table = NULL, dist = NULL, grp_var, y = clr, scale = TRUE, axes_arrows = F, ellipse = FALSE, ellipse.prob = 0.68, main = NULL, subtitle = NULL, legend_title = NULL ) ```

## Arguments

 `micro_set` A tidy_micro data set `table` OTU table of interest `dist` A distance matrix, such as a beta diversity. If supplied a PCoA plot will be returned `grp_var` Categorical grouping variable `y` Value to calculate principle components or coordinates on. Default is centered log ratio (recommended) `scale` Logical. Indicating whether the variables should be scaled to have unit variance before the analysis takes place `axes_arrows` Logical. Plot component axes arrows `ellipse` Logical. Plot normal data ellipses by groups `ellipse.prob` Numeric. `main` Plot title `subtitle` Plot subtitle `legend_title` Legend title

## Details

PCA calculation is done by a singular value decomposition of the (centered and possibly scaled) data matrix, not by using eigen on the covariance matrix. This is generally the preferred method for numerical accuracy. Calculations are accomplished through the `prcomp` function, and the plot is created through internal code based on the ggbiplot function https://github.com/vqv/ggbiplot.

## Value

A ggplot you can add geoms to if you'd like

## References

Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) The New S Language. Wadsworth & Brooks/Cole.

Mardia, K. V., J. T. Kent, and J. M. Bibby (1979) Multivariate Analysis, London: Academic Press.

Venables, W. N. and B. D. Ripley (2002) Modern Applied Statistics with S, Springer-Verlag.

Vincent Q. Vu (2011). ggbiplot: A ggplot2 based biplot. https://github.com/vqv/ggbiplot

## Examples

 ``` 1 2 3 4 5 6 7 8 9 10 11``` ```data(mrsa_gen); data(mrsa_clin) set <- tidy_micro(otu_tabs = mrsa_gen, tab_names = "Genus", clinical = mrsa_clin) ## PCA Plot set %>% micro_pca(table = "Genus", grp_var = Aureus_Positive) ## PCoA Plot (Recommended for p > n) bray_beta <- set %>% beta_div(table = "Genus") micro_pca(set, dist = bray_beta, grp_var = Aureus_Positive, ellipse = TRUE) ```

tidyMicro documentation built on Jan. 13, 2021, 6:18 a.m.