Skip to contents

Visualize the number of observations per sample.

Usage

rare_stacked(
  biom,
  rline = TRUE,
  counts = TRUE,
  labels = TRUE,
  y.trans = "log10",
  ...
)

Arguments

biom

An rbiom object, such as from as_rbiom(). Any value accepted by as_rbiom() can also be given here.

rline

Where to draw a horizontal line on the plot, intended to show a particular rarefaction depth. Set to TRUE to show an auto-selected rarefaction depth, FALSE to not show a line, or an integer for a custom position. Default: TRUE.

counts

Display the number of samples and reads remaining after rarefying to rline reads per sample. Default: TRUE.

labels

Show sample names under each bar. Default: TRUE.

y.trans

The transformation to apply to the y-axis. Visualizing differences of both high- and low-abundance taxa is best done with a non-linear axis. Options are:

  • "sqrt" - square-root transformation

  • "log1p" - log(y + 1) transformation

  • NULL - no transformation

These methods allow visualization of both high- and low-abundance taxa simultaneously, without complaint about 'zero' count observations. Default: "sqrt"

...

Additional parameters to pass along to ggplot2 functions. Prefix a parameter name with r. to ensure it gets passed to (and only to) geom_hline. For instance, r.color = "black" ensures only the horizontal rarefaction line has its color set to "black".

trans

Y-axis transformation. Options are "log10" or NULL. Default: "log10".

Value

A ggplot2 plot.
The computed data points and ggplot command are available as $data and $code, respectively.

Examples

    library(rbiom)
    
    rare_stacked(hmp50)

    
    rare_stacked(hmp50, rline = 500, r.size = 2, r.linetype = "twodash")

    
    fig <- rare_stacked(hmp50, counts = FALSE)
    fig$code
#> ggplot(data) +
#>   geom_rect(
#>     mapping = aes(xmin = .xmin, xmax = .xmax, ymin = .ymin, ymax = .ymax, fill = .group), 
#>     color   = NA ) +
#>   geom_hline(
#>     yintercept = 1183, 
#>     color      = "red", 
#>     linetype   = "dashed" ) +
#>   labs(
#>     fill = "Reads", 
#>     y    = ".ymax (log10 scale)" ) +
#>   scale_x_discrete() +
#>   scale_y_continuous(
#>     labels = scales::label_number(scale_cut = scales::cut_si("")), 
#>     expand = c(0, 0), 
#>     trans  = "log10" ) +
#>   theme_bw() +
#>   theme(
#>     text               = element_text(size = 14), 
#>     panel.grid.major.x = element_blank() )