plotAbundance {miaViz} | R Documentation

## Plotting abundance data

### Description

`plotAbundance` plots the abundance on a selected taxonomic rank. Since this probably makes sense only for relative abundance data, the assay used by default is expected to be in the slot ‘relabundance’. If only ‘counts’ is present, the relative abundance is computed.

### Usage

    plotAbundance(x, ...)

    ## S4 method for signature 'SummarizedExperiment'
    plotAbundance(
      x,
      rank = taxonomyRanks(x)[1],
      features = NULL,
      order_rank_by = c("name", "abund", "revabund"),
      order_sample_by = NULL,
      decreasing = TRUE,
      use_relative = TRUE,
      layout = c("bar", "point"),
      one_facet = TRUE,
      ncol = 2,
      scales = "fixed",
      abund_values = "counts",
      ...
    )

### Arguments

`x` | a `SummarizedExperiment` object.
`...` | additional parameters for plotting. See `mia-plot-args` for more details i.e. call `help("mia-plot-args")`
`rank` | a single `character` value defining the taxonomic rank to use. Must be a value of `taxonomyRanks(x)`.
`features` | a single `character` value defining a column from `colData` to be plotted below the abundance plot. Continuous numeric values will be plotted as point, whereas factors and character will be plotted as colour-code bar. (default: `features = NULL`)
`order_rank_by` | How to order abundance value: By name (“name”) for sorting the taxonomic labels alphabetically, by abundance (“abund”) to sort by abundance values or by a reverse order of abundance values (“revabund”).
`order_sample_by` | A single character value from the chosen rank of abundance data or from `colData` to select values to order the abundance plot by. (default: `order_sample_by = NULL`)
`decreasing` | TRUE or FALSE: If the `order_sample_by` is defined and the values are numeric, should the values used to order in decreasing or increasing fashion? (default: `decreasing = FALSE`)
`use_relative` | `TRUE` or `FALSE`: Should the relative values be calculated? (default: `use_relative = TRUE`)
`layout` | Either “bar” or “point”.
`one_facet` | Should the plot be returned in on facet or split into different facet, one facet per different value detect in `rank`. If `features` or `order_sample_by` is not `NULL`, this setting will be disregarded.
`ncol, scales` | if `one_facet = FALSE`, `ncol` defines many columns should be for plotting the different facets and `scales` is used to define the behavior of the scales of each facet. Both values are passed onto `facet_wrap`.
`abund_values` | a `character` value defining which assay data to use. (default: `abund_values = "relabundance"`)

### Details

Subsetting to rows of interested and ordering of those is expected to be done outside of this functions, e.g. `x[1:2,]`. This will plot data of all features present.

### Value

a `ggplot` object or list of two `ggplot` objects, if `features` are added to the plot.

### Examples

    data(GlobalPatterns, package="mia")
    se <- GlobalPatterns

    ## Plotting abundance using the first taxonomic rank as default
    plotAbundance(se, abund_values="counts")

    ## Using "Phylum" as rank
    plotAbundance(se, abund_values="counts", rank = "Phylum", add_legend = FALSE)

    ## If rank is set to NULL plotAbundance behaves like plotExpression
    plotAbundance(se, abund_values="counts", rank = NULL,
               features = head(rownames(se)))

    ## A feature from colData or taxon from chosen rank can be used for ordering samples.
    plotAbundance(se, abund_values="counts", rank = "Phylum",
               order_sample_by = "Bacteroidetes")

    ## Features from colData can be plotted together with abundance plot.
    # Returned object is a list that includes two plot; other visualizes abundance
    # other features.
    plot <- plotAbundance(se, abund_values = "counts", rank = "Phylum",
                       features = "SampleType")

    # These two plots can be combined with wrap_plots function from patchwork package
    library(patchwork)
    wrap_plots(plot, ncol = 1)

    ## Compositional barplot with top 5 taxa and samples sorted by "Bacteroidetes"

    # Getting top taxa on a Phylum level
    se <- relAbundanceCounts(se)
    se_phylum <- agglomerateByRank(se, rank ="Phylum", onRankOnly=TRUE)
    top_taxa <- getTopTaxa(se_phylum,top = 5, abund_values = "relabundance")

    # Renaming the "Phylum" rank to keep only top taxa and the rest to "Other"
    phylum_renamed <- lapply(rowData(se)$Phylum,
                           function(x){if (x %in% top_taxa) {x} else {"Other"}})
    rowData(se)$Phylum <- as.character(phylum_renamed)

    # Compositional barplot
    plotAbundance(se, abund_values="relabundance", rank = "Phylum",
               order_rank_by="abund", order_sample_by = "Bacteroidetes")

[Package miaViz version 1.2.1 Index]