plotRDA and plotCCA create an RDA/CCA plot starting from the output of CCA and RDA functions, two common methods for supervised ordination of microbiome data.

plotCCA(object, ...)

# S4 method for SingleCellExperiment
plotCCA(object, dimred, ...)

# S4 method for matrix
plotCCA(object, ...)

plotRDA(object, ...)

# S4 method for SingleCellExperiment
plotRDA(
  object,
  dimred,
  add.ellipse = TRUE,
  ellipse.alpha = 0.2,
  ellipse.linewidth = 0.1,
  ellipse.linetype = 1,
  vec.size = 0.5,
  vec.color = vec.colour,
  vec.colour = "black",
  vec.linetype = 1,
  arrow.size = 0.25,
  label.color = label.colour,
  label.colour = "black",
  label.size = 4,
  vec.text = TRUE,
  repel.labels = TRUE,
  sep.group = "—",
  repl.underscore = " ",
  add.significance = TRUE,
  add.expl.var = TRUE,
  add.vectors = TRUE,
  parse.labels = TRUE,
  ...
)

# S4 method for matrix
plotRDA(object, ...)

Arguments

object

a TreeSummarizedExperiment or a matrix of weights. The latter is returned as output from calculateRDA.

...

additional parameters for plotting, inherited from plotReducedDim, geom_label and geom_label_repel.

dimred

A string or integer scalar indicating the reduced dimension to plot. This is the output of runRDA and resides in reducedDim(tse, dimred).

add.ellipse

One of c(TRUE, FALSE, "fill", "colour", "color"), indicating whether ellipses should be present, absent, filled or colored. (default: ellipse.fill = TRUE)

ellipse.alpha

Number between 0 and 1 to adjust the opacity of ellipses. (default: ellipse.alpha = 0.2)

ellipse.linewidth

Number specifying the size of ellipses. (default: ellipse.linewidth = 0.1)

ellipse.linetype

Discrete number specifying the style of ellipses. (default: ellipse.linetype = 1)

vec.size

Number specifying the size of vectors. (default: vec.size = 0.5)

vec.color

Alias for vec.colour.

vec.colour

String specifying the colour of vectors. (default: vec.color = "black")

vec.linetype

Discrete number specifying the style of vector lines. (default: vec.linetype = 1)

arrow.size

Number specifying the size of arrows. (defaults: arrow.size = 0.25)

label.color

Alias for label.colour.

label.colour

String specifying the colour of text and labels. (default: label.color = "black")

label.size

Number specifying the size of text and labels. (default: label.size = 4)

vec.text

TRUE or FALSE, should text instead of labels be used to label vectors. (default: vec.text = TRUE)

repel.labels

TRUE or FALSE, should labels be repelled. (default: repel.labels = TRUE)

sep.group

String specifying the separator used in the labels. (default: sep.group = "\U2014")

repl.underscore

String used to replace underscores in the labels. (default: repl.underscore = " ")

add.significance

TRUE or FALSE, should explained variance and p-value appear in the labels. (default: add.significance = TRUE)

add.expl.var

TRUE or FALSE, should explained variance appear on the coordinate axes. (default: add.expl.var = TRUE)

add.vectors

TRUE or FALSE, should vectors appear in the plot. (default: add.vectors = TRUE)

parse.labels

TRUE or FALSE, should labels be parsed. (default: parse.labels = TRUE)

Value

A ggplot2 object

Details

plotRDA and plotCCA create an RDA/CCA plot starting from the output of CCA and RDA functions, two common methods for supervised ordination of microbiome data. Either a TreeSummarizedExperiment or a matrix object is supported as input. When the input is a TreeSummarizedExperiment, this should contain the output of runRDA in the reducedDim slot and the argument dimred needs to be defined. When the input is a matrix, this should be returned as output from calculateRDA. However, the first method is recommended because it provides the option to adjust aesthetics to the colData variables through the arguments inherited from plotReducedDim.

Examples

# Load dataset
library(miaViz)
data("enterotype", package = "mia")
tse <- enterotype
 
# Run RDA and store results into TreeSE
tse <- runRDA(tse,
              formula = assay ~ ClinicalStatus + Gender + Age,
              FUN = vegan::vegdist,
              distance = "bray",
              na.action = na.exclude)
               
# Create RDA plot coloured by variable
plotRDA(tse, "RDA",
        colour_by = "ClinicalStatus")
#> Warning: Removed 243 rows containing non-finite outside the scale range
#> (`stat_ellipse()`).
#> Too few points to calculate an ellipse
#> Too few points to calculate an ellipse
#> Warning: Removed 243 rows containing missing values or values outside the scale range
#> (`geom_point()`).

 
# Create RDA plot with empty ellipses
plotRDA(tse, "RDA",
        colour_by = "ClinicalStatus",
        add.ellipse = "colour")
#> Warning: Removed 243 rows containing non-finite outside the scale range
#> (`stat_ellipse()`).
#> Too few points to calculate an ellipse
#> Too few points to calculate an ellipse
#> Warning: Removed 243 rows containing missing values or values outside the scale range
#> (`geom_point()`).

 
# Create RDA plot with text encased in labels
plotRDA(tse, "RDA",
        colour_by = "ClinicalStatus",
        vec.text = FALSE)
#> Warning: Removed 243 rows containing non-finite outside the scale range
#> (`stat_ellipse()`).
#> Too few points to calculate an ellipse
#> Too few points to calculate an ellipse
#> Warning: Removed 243 rows containing missing values or values outside the scale range
#> (`geom_point()`).

 
# Create RDA plot without repelling text
plotRDA(tse, "RDA",
        colour_by = "ClinicalStatus",
        repel.labels = FALSE)
#> Warning: Removed 243 rows containing non-finite outside the scale range
#> (`stat_ellipse()`).
#> Too few points to calculate an ellipse
#> Too few points to calculate an ellipse
#> Warning: Removed 243 rows containing missing values or values outside the scale range
#> (`geom_point()`).

 
# Create RDA plot without vectors
plotRDA(tse, "RDA",
        colour_by = "ClinicalStatus",
        add.vectors = FALSE)
#> Warning: 'add.vectors' is FALSE, so other arguments for vectors and labels will be disregarded.
#> Warning: Removed 243 rows containing non-finite outside the scale range
#> (`stat_ellipse()`).
#> Too few points to calculate an ellipse
#> Too few points to calculate an ellipse
#> Warning: Removed 243 rows containing missing values or values outside the scale range
#> (`geom_point()`).

 
# Calculate RDA as a separate object
rda_mat <- calculateRDA(tse,
                        formula = assay ~ ClinicalStatus + Gender + Age,
                        FUN = vegan::vegdist,
                        distance = "bray",
                        na.action = na.exclude)
 
# Create RDA plot from RDA matrix
plotRDA(rda_mat)