Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

plot_bar

A flexible, informative barplot phyloseq data


Description

There are many useful examples of phyloseq barplot graphics in the phyloseq online tutorials. This function wraps ggplot2 plotting, and returns a ggplot2 graphic object that can be saved or further modified with additional layers, options, etc. The main purpose of this function is to quickly and easily create informative summary graphics of the differences in taxa abundance between samples in an experiment.

Usage

plot_bar(physeq, x="Sample", y="Abundance", fill=NULL,
 title=NULL, facet_grid=NULL)

Arguments

physeq

(Required). An otu_table-class or phyloseq-class.

x

(Optional). Optional, but recommended, especially if your data is comprised of many samples. A character string. The variable in the melted-data that should be mapped to the x-axis. See psmelt, melt, and ggplot for more details.

y

(Optional). A character string. The variable in the melted-data that should be mapped to the y-axis. Typically this will be "Abundance", in order to quantitatively display the abundance values for each OTU/group. However, alternative variables could be used instead, producing a very different, though possibly still informative, plot. See psmelt, melt, and ggplot for more details.

fill

(Optional). A character string. Indicates which sample variable should be used to map to the fill color of the bars. The default is NULL, resulting in a gray fill for all bar segments.

title

(Optional). Default NULL. Character string. The main title for the graphic.

facet_grid

(Optional). A formula object. It should describe the faceting you want in exactly the same way as for facet_grid, and is ulitmately provided to ggplot2 graphics. The default is: NULL, resulting in no faceting.

Value

A ggplot2 graphic object – rendered in the graphical device as the default print/show method.

See Also

Examples

data("GlobalPatterns")
gp.ch = subset_taxa(GlobalPatterns, Phylum == "Chlamydiae")
plot_bar(gp.ch)
plot_bar(gp.ch, fill="Genus")
plot_bar(gp.ch, x="SampleType", fill="Genus")
plot_bar(gp.ch, "SampleType", fill="Genus", facet_grid=~Family)
# See additional examples in the plot_bar online tutorial. Link above.

phyloseq

Handling and analysis of high-throughput microbiome census data

v1.34.0
AGPL-3
Authors
Paul J. McMurdie <joey711@gmail.com>, Susan Holmes <susan@stat.stanford.edu>, with contributions from Gregory Jordan and Scott Chamberlain
Initial release
2019-04-23

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.