nb_bars: Create stacked bar charts based on negative binomial model...

Description Usage Arguments Value Examples

View source: R/nb_bars.R

Description

nb_bars takes the output from nb_mods and creates stacked bar charts of the estimated relative abundance for each taxa. The benefit of modeling each taxa before created stacked bar charts is the ability to control for potential confounders. The function will facet wrap interaction terms. Currently, only quant_style "discrete" can be used for an interaction between two quantitative variables

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
nb_bars(
  modsum,
  ...,
  range,
  quant_style = c("continuous", "discrete"),
  top_taxa = 0,
  RA = 0,
  specific_taxa = NULL,
  lines = TRUE,
  xaxis,
  main,
  subtitle,
  xlab,
  ylab,
  facet_labels = NULL,
  facet_layout = 1
)

Arguments

modsum

The output from nb_mods

...

The covariate you'd like to plot. Can be an interaction term or main effect, but must be in the models created by nb_mods

range

The range you'd like to plot over for a quantitative variable. Will default to the IQR

quant_style

"continuous" will plot over the entire range specified; "discrete" will plot only the endpoints of the range specified. "continuous" by default. This option is ignored without a quantitative variable

top_taxa

Only plot X taxa with the highest relative abundance. The rest will be aggregated into an "Other" category

RA

Only plot taxa with a relative abundance higher than X. The rest will be aggregated into an "Other" category

specific_taxa

Plot this specific taxa even if it doesn't meet the top_taxa or RA requirements

lines

Logical; Add outlines around the different taxa colors in the stacked bar charts

xaxis

Labels for the x-axis ticks. Most useful for categorical variables and defaults to the levels

main

Plot title

subtitle

Subtitle for the plot

xlab

x-axis label

ylab

y-axis label

facet_labels

Labels for the facets created for interaction terms

facet_layout

Rearrange the facets created for interaction terms

Value

Returns a ggplot that you can add geoms to if you'd like

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
data(bpd_phy); data(bpd_cla); data(bpd_ord); data(bpd_fam); data(bpd_clin)
otu_tabs = list(Phylum = bpd_phy, Class = bpd_cla,
Order = bpd_ord, Family = bpd_fam)

set <- tidy_micro(otu_tabs = otu_tabs, clinical = bpd_clin) %>%
filter(day == 7) ## Only including the first week

## Creating negative binomial models on filtered tidy_micro set
nb_fam <- set %>%
otu_filter(ra_cutoff = 0.1, exclude_taxa = c("Unclassified", "Bacteria")) %>%
nb_mods(table = "Family", bpd1)

nb_fam %>%
nb_bars(bpd1, top_taxa = 9, xlab = "BPD Severity")

Example output

Loading required package: tidyverse
── Attaching packages ─────────────────────────────────────── tidyverse 1.3.0 ──
✔ ggplot2 3.3.2purrr   0.3.4tibble  3.0.4dplyr   1.0.2tidyr   1.1.2stringr 1.4.0readr   1.4.0forcats 0.5.0
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()dplyr::lag()    masks stats::lag()
Contains 74 libraries from OTU files.

Summary of sequencing depth:
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
   8851   24938   33314   36650   43590   97408 
Filter for Class counts


Found 'Unclassified' category in input data.

Created new 'Other' category.

Found 'Bacteria' category in input data.

Found 34 OTUs.

Collapsed 2 OTUs into 'Other' in OTU table.

Converted 61662 counts to 'Other' otu category.

Remaining OTUs: 33 (Including 'Other').


Relative abundance cutoff: 0.1% (i.e., at least one library must have RA > 0.1% to keep OTU).

Found 33 OTUs.

Found 'Other' category in input data.

Collapsed 24 OTUs into 'Other' in OTU table.

Converted 337 counts to 'Other' otu category.

Remaining OTUs: 9 (Including 'Other').


Filter for Family counts


Found 'Unclassified' category in input data.

Created new 'Other' category.

Found 'Bacteria' category in input data.

Found 116 OTUs.

Collapsed 2 OTUs into 'Other' in OTU table.

Converted 61662 counts to 'Other' otu category.

Remaining OTUs: 115 (Including 'Other').


Relative abundance cutoff: 0.1% (i.e., at least one library must have RA > 0.1% to keep OTU).

Found 115 OTUs.

Found 'Other' category in input data.

Collapsed 95 OTUs into 'Other' in OTU table.

Converted 751 counts to 'Other' otu category.

Remaining OTUs: 20 (Including 'Other').


Filter for Order counts


Found 'Unclassified' category in input data.

Created new 'Other' category.

Found 'Bacteria' category in input data.

Found 62 OTUs.

Collapsed 2 OTUs into 'Other' in OTU table.

Converted 61662 counts to 'Other' otu category.

Remaining OTUs: 61 (Including 'Other').


Relative abundance cutoff: 0.1% (i.e., at least one library must have RA > 0.1% to keep OTU).

Found 61 OTUs.

Found 'Other' category in input data.

Collapsed 45 OTUs into 'Other' in OTU table.

Converted 525 counts to 'Other' otu category.

Remaining OTUs: 16 (Including 'Other').


Filter for Phylum counts


Found 'Unclassified' category in input data.

Created new 'Other' category.

Found 'Bacteria' category in input data.

Found 15 OTUs.

Collapsed 2 OTUs into 'Other' in OTU table.

Converted 61662 counts to 'Other' otu category.

Remaining OTUs: 14 (Including 'Other').


Relative abundance cutoff: 0.1% (i.e., at least one library must have RA > 0.1% to keep OTU).

Found 14 OTUs.

Found 'Other' category in input data.

Collapsed 7 OTUs into 'Other' in OTU table.

Converted 50 counts to 'Other' otu category.

Remaining OTUs: 7 (Including 'Other').


Waiting for profiling to be done...
Waiting for profiling to be done...
Waiting for profiling to be done...
Waiting for profiling to be done...
Waiting for profiling to be done...
Waiting for profiling to be done...
Waiting for profiling to be done...
Waiting for profiling to be done...
Waiting for profiling to be done...
Waiting for profiling to be done...
Waiting for profiling to be done...
Waiting for profiling to be done...
Waiting for profiling to be done...
Waiting for profiling to be done...
Waiting for profiling to be done...
Waiting for profiling to be done...
Waiting for profiling to be done...
Waiting for profiling to be done...
Waiting for profiling to be done...

18 taxa converged.
2 taxa did not converge.
There were 50 or more warnings (use warnings() to see the first 50)
Warning messages:
1: Maximum column sum is 108 and will be rescaled to equal 100. 
2: Minimum column sum is 86 and will be rescaled to equal 100. 

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