plot_beta_diversity: plot_beta_diversity

View source: R/plot_beta_diversity.R

plot_beta_diversityR Documentation

plot_beta_diversity

Description

This is a function for plotting beta diversity.

Usage

plot_beta_diversity(
  phyloseq,
  feature,
  feature2 = NA,
  feature2_shape = c(0:21),
  level = NA,
  method = "bray",
  colors = NULL,
  size = 3,
  label = FALSE,
  group_column = NA,
  arrange_column = NA,
  add_pc1 = FALSE,
  add_pc1_otu_level = FALSE,
  add_pc1_cor_method = "spearman",
  add_pc2 = FALSE,
  add_pc2_otu_level = FALSE,
  add_pc2_cor_method = "spearman",
  print_to_screen = FALSE
)

Arguments

phyloseq

A phyloseq object contain OTU table, taxonomy table, sample metadata and phylogenetic tree, or a phyloseq object only contain constructed OTU table and metadata.

feature

The column name of the feature you want to select from metadata, e.g. "Phenotype".

feature2

The column name of another feature you want to select from metadata, which will show in different shape, e.g. "Gender". Default is NA.

feature2_shape

The shape values for feature2. See ggplot2::scale_shape_manual.

level

Which taxonomy level will be used to calculate beta diversity. Default is NA. If NA, the original OTU table in phyloseq will be used. If level is given, first an OTU table with taxonomy will be constructed using construct_otu_table, then the OTU table will be used to calculate beta diversity through phyloseq::distance. The level name should be one of "Kingdom", "Phylum", "Class", "Order", "Family", "Genus", "Species".

method

The method to calculate beta diversity. Method should be one of c("bray", "jaccard", "unifrac", "wunifrac"). Default is "bray". PS: "unifrac" and "wunifrac" require a phylogenetic tree.

colors

A vector of colors. The number of colors should be larger than the number of feature. Default is NULL, if NULL, plot_beta_diversity will use ggsci::jco theme for the plot.

size

Value for geom_point(size). Default is 3.

label

Default is FALSE. If TRUE, add sample name labels to plot.

group_column

The first parameter for adding arrows to the plot. Choose a column to group. The arrows will be added to each group.

arrange_column

The second parameter for adding arrows to the plot. Choose a column to arrange. This column should be continuous variables. Each group will be arrange by variables in this column, the first variable is where the arrow starts, pointing to the second and to the last variable.

add_pc1

Default is FALSE. If TRUE, plot out top 3 most correlated OTUs to PC1.

add_pc1_otu_level

Default is FALSE. If FALSE, add_pc1 will extract otu_table from phyloseq directly. If phyloseq object has both otu_table and tax_table, add_pc1_otu_level can get different taxonomy for top 3 most correlated OTUs in add_pc1. If "all", will plot all taxonomy level. Note: If 'level' argument is provided, the corresponding OTU with taxonomy will be used to compute correlation with PC1 and PC2 values, 'add_pc1_otu_level' and 'add_pc2_otu_level' need to be set to FALSE.

add_pc1_cor_method

The method for computing correlation between PC1 and OTUs. One of "spearman" (default), "kendall", or "pearson".

add_pc2

Same as add_pc1.

add_pc2_otu_level

Same as add_pc1_otu_level.

add_pc2_cor_method

Same as add_pc1_cor_method.

print_to_screen

Default is FALSE. If TRUE, print beta-diversity table to the screen.

Examples

plot_beta_diversity(demo_phyloseq_object, feature = "diagnosis")

yeguanhuav/visualization416S documentation built on March 22, 2022, 9:03 p.m.