plot_stacked_bar: plot_stacked_bar

plot_stacked_barR Documentation

plot_stacked_bar

Description

This is a function for stacked barplot. PS: When faceting the stacked bar plot, use facet_wrap( vars(column_name), scales = "free_x")

Usage

plot_stacked_bar(
  phyloseq = NULL,
  level = NA,
  feature = NA,
  otu_table = NULL,
  metadata = NULL,
  order = NULL,
  relative_abundance = TRUE,
  legend_position = "top",
  colors = NULL,
  collapse = 0.01,
  title = NA,
  x_text_angle = 90
)

Arguments

phyloseq

A phyloseq object contain otu table, taxonomy table, sample metadata and phylogenetic tree. Set it to NULL if using an OTU table and metadata to draw the stacked barplot.

level

A taxonomy level to plot stacked bar. Default is NA. Required when using phyloseq object.

feature

The feature that will show as a colorbar under x axis. Default is NA.

otu_table

An OTU table. Taxa are colnames, SampleID are rownames (just like phyloseq). Set it to NULL if using phyloseq.

metadata

A metadata for the OTU table. SampleID are rownames (just like phyloseq). Set it to NULL if using phyloseq.

order

A vector of arranged SampleID in wanted order. Default is NULL. If NULL, plot_stacked_bar will automatically arrange samples by the most abundance taxonomy in decreasing order.

relative_abundance

Turn plot into relative abundance or not. Default is TRUE.

legend_position

Legend position. Default is "top". legend_position should be one of "none", "left", "right", "bottom", "top".

colors

A vector of colors. The number of colors should be larger than the number of level. Default is NULL, if NULL, plot_stacked_bar will use distinctive_colors for the plot.

collapse

Default is 0.01, collapse taxonomy which abundance is lower than 1 percent of total into "Others". Set it to FALSE if want to show all taxonomy levels.

title

Default is NA, value for ggplot2::labs(title).

x_text_angle

Default is 90, value for ggplot2::ggplot(themt(axis.text.x = element_text( angle))).

Examples

# Minimum usage
plot_stacked_bar(demo_phyloseq_object, level = "Genus")

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