plot_tax_bar: Create a Taxa Bar Chart

View source: R/plot_tax_bar.R

plot_tax_barR Documentation

Create a Taxa Bar Chart

Description

plot_tax_bar() creates a taxa bar chart from the data frame generated by make_phy_df().

Usage

plot_tax_bar(
  taxa_df,
  rank,
  colours = NULL,
  sample = "X.SampleID",
  abund = "Abundance",
  legloc = "right",
  yscale = "lin",
  means = FALSE,
  r_ticks = FALSE,
  leglen = NULL
)

Arguments

rank

The taxonomic rank at which to view the data. Must be one of 'Genus', 'Family', 'Order', 'Class', 'Phylum'. May not be a lower rank than the rank given to make_phy_df().

colours

A character vector of colour names or hex values. Must have enough colours to accommodate all your taxa at the appropriate rank. If you don't provide one, there are a few internal vectors that have 21, 31, 60, or 70 colours that the function will try to use.

sample

'X.SampleID' The name of the sample column in the data frame.

abund

'Abundance' The name of the abundance column in the data frame.

legloc

'right' Location of the legend. Passed directly to ggplot2::theme(legend.position = legloc) and can be any of "none", "left", "right", "top", or "bottom". If it is anything else, ggplot2::theme() will default to "none".

yscale

[Deprecated] This function no longer supports y-axis scales other than linear.

means

FALSE If TRUE, sets position = fill in the ggplot2::geom_bar() to constrain the abundances to sum to 1. Good to use if your ⁠sample = ⁠ parameter is not actually sample names, but rather larger categories, to produce a plot of category means.

r_ticks

FALSE If TRUE x-axis tickmark text is rotated 90 degrees and read bottom-to-top.

leglen

NULL A non-negative integer that limits the number of taxa to show in the legend. Doesn't limit the number of taxa shown in the plot, just in the legend. You can reduce the number of taxa shown in the plot by increasing the cutoff value in make_phy_df(). If leglen is 0, no legend will be shown.

tax_df

The data frame used for plotting. Unless you really know what you're doing, use the data frame output by make_phy_df().

Details

This function generates a ggplot object that is a first-pass, reasonable attempt at a taxon bar chart. The taxa are ordered by mean abundance and the 'Other' category is at the top. Because it's a regular ggplot object, you can add more geoms or facet it or manipulate it however you like using ggplot functions.

Value

A ggplot object.


JCSzamosi/aftersl1p documentation built on July 3, 2025, 8:37 p.m.