plot_ra: Create an ordered relative abundance plot

Description Usage Arguments Value Examples

View source: R/plot_ra.R

Description

Create an ordered relative abundance plot

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
plot_ra(
  df,
  df_obs = NULL,
  taxon = "OTU",
  yvar = "Mean_Perc",
  title = "",
  error_bar = FALSE,
  facet_var = NULL,
  fill = NULL,
  phy_vec = NULL,
  fill_pal = NULL,
  gtxt = FALSE,
  seed = 123
)

Arguments

df

Dataframe containing metadata and taxon (Phylum, Otu, etc) abundance data in 'long' format, e.g. using gather. This dataframe is typically the result of processing via taxon_sort_gather.

df_obs

An optional dataframe containing individual observations, when df contains summarized samples. df_obs will be used to add a points layer with geom_jitter.

taxon

Which taxonomic level within df (and optionally, df_obs) should be plotted? OTU by default.

yvar

Variable to use on the y-axis. Defaults to Mean_Perc.

title

String to use as plot title. Defaults to an empty string.

error_bar

Boolean for whether to include an errorbar. If so, df should contain a column named SEM with this information.

facet_var

Variable to use for faceted plots. By default, no faceting will be used.

fill

Optional variable to use for fill color. Common use cases include filling by Phylum, Sample_name, or Sample_type.

phy_vec

Optional vector containing the unique Phyla resulting from load_tax, likely following trimming. Combined with fill_pal this allows for a consistent color scheme across RA plots.

fill_pal

An optional user-defined palette for maintaining consistent fill colors across RA plots. Best when combined with phy_vec.

gtxt

Boolean for whether to include a geom_text layer in the plot which will display actual percentages. Not included by default.

seed

Integer to be used as a random seed to ensure reproducibility. For example, this would come into play if using df_obs which will create a geom_jitter layer that adds random noise to points.

Value

A ggplot created based on df and the specified parameters. It can be further modified with additional layers.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
plot_ra(mock_df, title = "Cross-Comparison of Mock Control Replicates", yvar = "Percentage",
   facet_var = "Sample", fill = "Phylum", gtxt = T)

plot_ra(samp_df, title = "Exp1 & 2 Stomachs by Treatment, Ordered by Untreated",
   facet_var = "Group", fill = "Phylum", error_bar = T)

plot_ra(df = otu_agg, df_obs = otu_obs, title = "Feces Samples, Ordered by Day 0",
   facet_var = "Day", fill = "Phylum")

plot_ra(df = phy_agg, df_obs = phy_obs, taxon = "Phylum",
   title = "Feces Samples, Aggregated by Phylum, Ordered by Day 0",
   facet_var = "Day", fill = "Phylum", phy_vec = phy_rank$Phylum, fill_pal = phy_pal)

cb-42/cbmbtools documentation built on Jan. 9, 2021, 1:38 a.m.