Title: | Microbiome Analysis Plotting and Visualization |
---|---|
Description: | The miaViz package implements functions to visualize TreeSummarizedExperiment objects especially in the context of microbiome analysis. Part of the mia family of R/Bioconductor packages. |
Authors: | Tuomas Borman [aut, cre] , Felix G.M. Ernst [aut] , Leo Lahti [aut] , Basil Courbayre [ctb], Giulio Benedetti [ctb] , Théotime Pralas [ctb], Nitesh Turaga [ctb], Chouaib Benchraka [ctb], Sam Hillman [ctb], Muluh Muluh [ctb], Noah De Gunst [ctb], Ely Seraidarian [ctb], Himmi Lindgren [ctb], Vivian Ikeh [ctb] |
Maintainer: | Tuomas Borman <[email protected]> |
License: | Artistic-2.0 | file LICENSE |
Version: | 1.15.2 |
Built: | 2024-11-02 03:27:14 UTC |
Source: | https://github.com/bioc/miaViz |
The scope of this package is the plotting and visualization of microbiome
data. The main class for interfacing is the TreeSummarizedExperiment
class.
Maintainer: Tuomas Borman [email protected] (ORCID)
Authors:
Felix G.M. Ernst [email protected] (ORCID)
Leo Lahti [email protected] (ORCID)
Other contributors:
Basil Courbayre [contributor]
Giulio Benedetti [email protected] (ORCID) [contributor]
Théotime Pralas [contributor]
Nitesh Turaga [contributor]
Chouaib Benchraka [contributor]
Sam Hillman [contributor]
Muluh Muluh [contributor]
Noah De Gunst [contributor]
Ely Seraidarian [contributor]
Himmi Lindgren [contributor]
Vivian Ikeh [contributor]
mia class
getNeatOrder
sorts already ordinated data by the radial
theta angle. This method is useful for organizing data points based on their
angular position in a 2D space, typically after an ordination technique such
as PCA or NMDS has been applied.
The function takes in a matrix of ordinated data, optionally
centers the data using specified methods (mean
, median
, or
NULL
), and then calculates the angle (theta) for each point relative
to the centroid. The data points are then sorted based on these theta values
in ascending order.
One significant application of this sorting method is in plotting heatmaps. By using radial theta sorting, the relationships between data points can be preserved according to the ordination method's spatial configuration, rather than relying on hierarchical clustering, which may distort these relationships. This approach allows for a more faithful representation of the data's intrinsic structure as captured by the ordination process.
getNeatOrder(x, centering = "mean", ...) ## S4 method for signature 'matrix' getNeatOrder(x, centering = "mean", ...)
getNeatOrder(x, centering = "mean", ...) ## S4 method for signature 'matrix' getNeatOrder(x, centering = "mean", ...)
x |
A matrix containing the ordinated data to be sorted. Columns should represent the principal components (PCs) and rows should represent the entities being analyzed (e.g. features or samples). There should be 2 columns only representing 2 PCs. |
centering |
|
... |
Additional arguments passed to other methods. |
It's important to note that the sechm package does actually have the functionality for plotting a heatmap using this radial theta angle ordering, though only by using an MDS ordination.
That being said, the getNeatOrder
function is more modular and
separate to the plotting, and can be applied to any kind of ordinated data
which can be valuable depending on the use case.
Rajaram & Oono (2010) NeatMap - non-clustering heat map alternatives in R outlines this in more detail.
A character
vector of row indices in the sorted order.
# Load the required libraries and dataset library(mia) library(scater) library(ComplexHeatmap) library(circlize) data(peerj13075) # Group data by taxonomic order tse <- agglomerateByRank(peerj13075, rank = "order", onRankOnly = TRUE) # Transform the samples into relative abundances using CLR tse <- transformAssay( tse, assay.type = "counts", method="clr", MARGIN = "cols", name="clr", pseudocount = TRUE) # Transform the features (taxa) into zero mean, unit variance # (standardize transformation) tse <- transformAssay( tse, assay.type="clr", method="standardize", MARGIN = "rows") # Perform PCA using calculatePCA res <- calculatePCA(tse, assay.type = "standardize", ncomponents = 10) # Sort by radial theta and sort the original assay data sorted_order <- getNeatOrder(res[, c(1,2)], centering = "mean") tse <- tse[, sorted_order] # Define the color function and cap the colors at [-5, 5] col_fun <- colorRamp2(c(-5, 0, 5), c("blue", "white", "red")) # Create the heatmap heatmap <- Heatmap(assay(tse, "standardize"), name = "NeatMap", col = col_fun, cluster_rows = FALSE, # Do not cluster rows cluster_columns = FALSE, # Do not cluster columns show_row_dend = FALSE, show_column_dend = FALSE, row_names_gp = gpar(fontsize = 4), column_names_gp = gpar(fontsize = 6), heatmap_width = unit(20, "cm"), heatmap_height = unit(15, "cm") )
# Load the required libraries and dataset library(mia) library(scater) library(ComplexHeatmap) library(circlize) data(peerj13075) # Group data by taxonomic order tse <- agglomerateByRank(peerj13075, rank = "order", onRankOnly = TRUE) # Transform the samples into relative abundances using CLR tse <- transformAssay( tse, assay.type = "counts", method="clr", MARGIN = "cols", name="clr", pseudocount = TRUE) # Transform the features (taxa) into zero mean, unit variance # (standardize transformation) tse <- transformAssay( tse, assay.type="clr", method="standardize", MARGIN = "rows") # Perform PCA using calculatePCA res <- calculatePCA(tse, assay.type = "standardize", ncomponents = 10) # Sort by radial theta and sort the original assay data sorted_order <- getNeatOrder(res[, c(1,2)], centering = "mean") tse <- tse[, sorted_order] # Define the color function and cap the colors at [-5, 5] col_fun <- colorRamp2(c(-5, 0, 5), c("blue", "white", "red")) # Create the heatmap heatmap <- Heatmap(assay(tse, "standardize"), name = "NeatMap", col = col_fun, cluster_rows = FALSE, # Do not cluster rows cluster_columns = FALSE, # Do not cluster columns show_row_dend = FALSE, show_column_dend = FALSE, row_names_gp = gpar(fontsize = 4), column_names_gp = gpar(fontsize = 6), heatmap_width = unit(20, "cm"), heatmap_height = unit(15, "cm") )
These example data objects were prepared to serve as examples. See the details for more information.
data(col_graph) data(row_graph) data(row_graph_order)
data(col_graph) data(row_graph) data(row_graph_order)
An object of class tbl_graph
(inherits from igraph
) of length 26.
An object of class tbl_graph
(inherits from igraph
) of length 996.
An object of class tbl_graph
(inherits from igraph
) of length 110.
For *_graph
data:
“Jaccard” distances were calculated via
calculateDistance(genus, FUN = vegan::vegdist, method = "jaccard",
exprs_values = "relabundance")
, either using transposed assay data or not
to calculate distances for samples or features. NOTE: the function
mia::calculateDistance is now deprecated.
“Jaccard” dissimilarites were converted to similarities and values
above a threshold were used to construct a graph via
graph.adjacency(mode = "lower", weighted = TRUE)
.
The igraph
object was converted to tbl_graph
via
as_tbl_graph
from the tidygraph
package.
To be able to fine tune plotting, several additional plotting arguments are available. These are described on this page.
line.alpha
: Numeric scalar
in [0, 1]
, Specifies the
transparency of the tree edges. (Default: 1
)
line.width
: Numeric scalar
. Specifies the default width of
an edge. (Default: NULL
) to use default of the ggtree
package.
line.width.range
: Numeric vector
. The range for plotting
dynamic edge widths in. (Default: c(0.5,3)
)
point.alpha
: Numeric scalar
in [0, 1]
. Specifies the
transparency of the tips. (Defaults: 1
)
point.size
: Numeric scalar
. Specifies the
default size of tips. (Defaults: 2.
)
point.size.range
: Numeric vector
. Specifies the range for plotting
dynamic tip sizes in. (Defaults: c(1,4)
)
label.font.size
: Numeric scalar
. Font size for the tip and
node labels. (Default: 3
)
highlight.font.size
: Numeric scalar
. Font size for the
highlight labels. (Default: 3
)
line.alpha
: Numeric scalar
in [0, 1]
. Specifies the
transparency of the tree edges. (Default: 1
)
line.width
: Numeric scalar
. Specifies the default width of
an edge. (Default: NULL
) to use default of the ggtree
package.
line.width.range
: Numeric vector
. The range for plotting
dynamic edge widths in. (Default: c(0.5,3)
)
point.alpha
: Numeric scalar
in [0, 1]
. Specifies the
transparency of the tips. (Default: 1
)
point.size
: Numeric scalar
. Specifies the
default size of tips. (Default: 2.
)
point.size.range
: Numeric vector
. The range for plotting
dynamic tip sizes in. (Default: c(1,4)
)
flipped
: Logical scalar
. Should the plot be flipped? (Default:
FALSE
)
add.legend
: Logical scalar
. Should legends be plotted?
(Default: TRUE
)
add.x.text
: Logical scalar
. Should x tick labels be plotted?
(Default: FALSE
)
add.border
: Logical scalar
. Should border of bars be plotted?
(Default: FALSE
)
bar.alpha
: Numeric scalar
in [0, 1]
. Specifies the
transparency of the bars. (Default: 1
)
point.alpha
: Numeric scalar
in [0, 1]
. Specifies the
transparency of the points. (Default: 1
)
point.size
: Numeric scalar
. Specifies the
default size of points. (Default: 2.
)
add.legend
: Logical scalar
. Should legends be plotted?
(Defaults: TRUE
)
point.shape
: Numeric scalar
. Sets the shape of points.
(Default: 21
)
point.colour
: Character scalar
. Specifies the
default colour of points. (Default: 2.
)
point.size
: Numeric scalar
. Specifies the
default size of points. (Default: 2.
)
point.alpha
: Numeric scalar
in [0, 1]
. Specifies the
transparency of the points. (Default: 1
)
flipped
: Logical scalar
. Should the plot be flipped? (Default:
FALSE
)
scales.free
: Logical scalar
. Should scales = "free"
be
set for faceted plots? (Default: TRUE
)
angle.x.text
: Logical scalar
. Should x tick labels be plotted?
(Default: FALSE
)
flipped
: Logical scalar
. Specifies whether the plot should
be flipped. (Default: FALSE
)
add.legend
: Logical scalar
. Should legends be plotted?
(Default: TRUE
)
point.alpha
: Numeric scalar
in [0, 1]
. Specifies the
transparency of the tips. (Default: 1
)
point.size
: Numeric scalar
. Specifies the
default size of tips. (Default: 2.
)
line.alpha
: Numeric scalar
in [0, 1]
. Specifies the
transparency of the tree edges. (Default: 1
)
line.type
: Numeric scalar
. Specifies the default line type.
(Default: NULL
) to use default of the ggplot2
package.
line.size
: Numeric scalar
. Specifies the default width of
a line. (Default: NULL
) to use default of the ggplot2
package.
add.legend
: Logical scalar
. Should legends be plotted?
(Default: TRUE
)
line.alpha
: Numeric scalar
in [0, 1]
. Specifies the
transparency of the tree edges. (Default: 1
)
line.type
: Numeric scalar
. Specifies the default line type.
(Default: NULL
) to use default of the ggplot2
package.
line.width
: Numeric scalar
. Specifies the default width of
a line. (Default: NULL
) to use default of the ggplot2
package.
line.width.range
: Numeric vector
. The range for plotting
dynamic line widths in. (Default: c(0.5,3)
)
ribbon.alpha
: Numeric scalar
in [0, 1]
. Specifies the
transparency of the ribbon. (Default: 0.3
)
add.legend
: Logical scalar
. Should legends be plotted?
(Default: TRUE
)
rect.alpha
: Numeric scalar
in [0, 1]
. Specifies the
transparency of the areas. (Default: 1
)
rect.colour
: Character scalar
. Specifies the colour to use
for colouring the borders of the areas. (Default: "black"
)
na.value
: Character scalar
. Specifies the colour to use
for NA
values. (Default: "grey80"
)
plotAbundance()
creates a barplot of feature abundances, typically
used to visualize the relative abundance of features at a specific taxonomy
rank.
plotAbundance(x, ...) ## S4 method for signature 'SummarizedExperiment' plotAbundance( x, assay.type = assay_name, assay_name = "counts", layout = "bar", ... )
plotAbundance(x, ...) ## S4 method for signature 'SummarizedExperiment' plotAbundance( x, assay.type = assay_name, assay_name = "counts", layout = "bar", ... )
x |
a
|
... |
additional parameters for plotting.
See |
assay.type |
|
assay_name |
Deprecate. Use |
layout |
|
It is recommended to handle subsetting, agglomeration, and transformation
outside this function. However, agglomeration and relative transformation
can be applied using the group
and as.relative
parameters,
respectively. If one of the TAXONOMY_RANKS
is selected via
group
, mia::agglomerateByRank()
is used, otherwise
agglomerateByVariable()
is applied.
a ggplot
object or list of two
ggplot
objects, if col.var
are added to
the plot.
data(GlobalPatterns, package="mia") tse <- GlobalPatterns # If rank is set to NULL (default), agglomeration is not done. However, note # that there is maximum number of rows that can be plotted. That is why # we take sample from the data. set.seed(26348) sample <- sample(rownames(tse), 20) tse_sub <- tse[sample, ] # Apply relative transformation tse_sub <- transformAssay(tse_sub, method = "relabundance") plotAbundance(tse_sub, assay.type = "relabundance") # Plotting counts using the first taxonomic rank as default plotAbundance( tse, assay.type="counts", group = "Phylum") + labs(y="Counts") # Using "Phylum" as rank. Apply relative transformation to "counts" assay. plotAbundance( tse, assay.type="counts", group = "Phylum", add_legend = FALSE, as.relative = TRUE) # Apply relative transform tse <- transformAssay(tse, method = "relabundance") # A feature from colData or taxon from chosen rank can be used for ordering # samples. plotAbundance( tse, assay.type="relabundance", group = "Phylum", order.col.by = "Bacteroidetes") # col.var from colData can be plotted together with abundance plot. # Returned object is a list that includes two plot; other visualizes ## abundance other col.var. plot <- plotAbundance( tse, assay.type = "relabundance", group = "Phylum", col.var = "SampleType") # These two plots can be combined with wrap_plots function from patchwork # package library(patchwork) wrap_plots(plot, ncol = 1, heights = c(0.95, 0.05)) # Same plot as above but showing sample IDs as labels for the x axis on the # top plot. Moreover, we use facets. plot <- plotAbundance( tse, assay.type = "relabundance", group = "Phylum", col.var = "SampleType", add.legend = FALSE, add.x.text = TRUE, facet.cols = TRUE, scales = "free_x") + theme(axis.text.x = element_text(angle = 90)) plot # Compositional barplot with top 5 taxa and samples sorted by # "Bacteroidetes" # Getting top taxa on a Phylum level tse <- transformAssay(tse, method = "relabundance") tse_phylum <- agglomerateByRank(tse, rank = "Phylum") top_taxa <- getTop(tse_phylum, top = 5, assay.type = "relabundance") # Renaming the "Phylum" rank to keep only top taxa and the rest to "Other" phylum_renamed <- lapply(rowData(tse)$Phylum, function(x){ if (x %in% top_taxa) {x} else {"Other"}}) rowData(tse)$Phylum <- as.character(phylum_renamed) # Compositional barplot plotAbundance( tse, assay.type="relabundance", group = "Phylum", order.row.by="abund", order.col.by = "Bacteroidetes")
data(GlobalPatterns, package="mia") tse <- GlobalPatterns # If rank is set to NULL (default), agglomeration is not done. However, note # that there is maximum number of rows that can be plotted. That is why # we take sample from the data. set.seed(26348) sample <- sample(rownames(tse), 20) tse_sub <- tse[sample, ] # Apply relative transformation tse_sub <- transformAssay(tse_sub, method = "relabundance") plotAbundance(tse_sub, assay.type = "relabundance") # Plotting counts using the first taxonomic rank as default plotAbundance( tse, assay.type="counts", group = "Phylum") + labs(y="Counts") # Using "Phylum" as rank. Apply relative transformation to "counts" assay. plotAbundance( tse, assay.type="counts", group = "Phylum", add_legend = FALSE, as.relative = TRUE) # Apply relative transform tse <- transformAssay(tse, method = "relabundance") # A feature from colData or taxon from chosen rank can be used for ordering # samples. plotAbundance( tse, assay.type="relabundance", group = "Phylum", order.col.by = "Bacteroidetes") # col.var from colData can be plotted together with abundance plot. # Returned object is a list that includes two plot; other visualizes ## abundance other col.var. plot <- plotAbundance( tse, assay.type = "relabundance", group = "Phylum", col.var = "SampleType") # These two plots can be combined with wrap_plots function from patchwork # package library(patchwork) wrap_plots(plot, ncol = 1, heights = c(0.95, 0.05)) # Same plot as above but showing sample IDs as labels for the x axis on the # top plot. Moreover, we use facets. plot <- plotAbundance( tse, assay.type = "relabundance", group = "Phylum", col.var = "SampleType", add.legend = FALSE, add.x.text = TRUE, facet.cols = TRUE, scales = "free_x") + theme(axis.text.x = element_text(angle = 90)) plot # Compositional barplot with top 5 taxa and samples sorted by # "Bacteroidetes" # Getting top taxa on a Phylum level tse <- transformAssay(tse, method = "relabundance") tse_phylum <- agglomerateByRank(tse, rank = "Phylum") top_taxa <- getTop(tse_phylum, top = 5, assay.type = "relabundance") # Renaming the "Phylum" rank to keep only top taxa and the rest to "Other" phylum_renamed <- lapply(rowData(tse)$Phylum, function(x){ if (x %in% top_taxa) {x} else {"Other"}}) rowData(tse)$Phylum <- as.character(phylum_renamed) # Compositional barplot plotAbundance( tse, assay.type="relabundance", group = "Phylum", order.row.by="abund", order.col.by = "Bacteroidetes")
This function plots abundance of the most abundant taxa.
plotAbundanceDensity(x, ...) ## S4 method for signature 'SummarizedExperiment' plotAbundanceDensity( x, layout = c("jitter", "density", "point"), assay.type = assay_name, assay_name = "counts", n = min(nrow(x), 25L), colour.by = colour_by, colour_by = NULL, shape.by = shape_by, shape_by = NULL, size.by = size_by, size_by = NULL, decreasing = order_descending, order_descending = TRUE, ... )
plotAbundanceDensity(x, ...) ## S4 method for signature 'SummarizedExperiment' plotAbundanceDensity( x, layout = c("jitter", "density", "point"), assay.type = assay_name, assay_name = "counts", n = min(nrow(x), 25L), colour.by = colour_by, colour_by = NULL, shape.by = shape_by, shape_by = NULL, size.by = size_by, size_by = NULL, decreasing = order_descending, order_descending = TRUE, ... )
x |
a
|
... |
additional parameters for plotting.
See |
layout |
|
assay.type |
|
assay_name |
Deprecate. Use |
n |
|
colour.by |
|
colour_by |
Deprecated. Use |
shape.by |
|
shape_by |
Deprecated. Use |
size.by |
|
size_by |
Deprecated. Use |
decreasing |
|
order_descending |
Deprecated. Use |
This function plots abundance of the most abundant taxa. Abundance can be plotted as a jitter plot, a density plot, or a point plot. By default, x-axis represents abundance and y-axis taxa. In a jitter and point plot, each point represents abundance of individual taxa in individual sample. Most common abundances are shown as a higher density.
A density plot can be seen as a smoothened bar plot. It visualized distribution of abundances where peaks represent most common abundances.
A ggplot2
object
Leo Lahti and Tuomas Borman. Contact: microbiome.github.io
data("peerj13075", package = "mia") tse <- peerj13075 # Plots the abundances of 25 most abundant taxa. Jitter plot is the default option. plotAbundanceDensity(tse, assay.type = "counts") # Counts relative abundances tse <- transformAssay(tse, method = "relabundance") # Plots the relative abundance of 10 most abundant taxa. # "nationality" information is used to color the points. X-axis is log-scaled. plotAbundanceDensity( tse, layout = "jitter", assay.type = "relabundance", n = 10, colour.by = "Geographical_location") + scale_x_log10() # Plots the relative abundance of 10 most abundant taxa as a density plot. # X-axis is log-scaled plotAbundanceDensity( tse, layout = "density", assay.type = "relabundance", n = 10 ) + scale_x_log10() # Plots the relative abundance of 10 most abundant taxa as a point plot. # Point shape is changed from default (21) to 41. plotAbundanceDensity( tse, layout = "point", assay.type = "relabundance", n = 10, point.shape = 41) # Plots the relative abundance of 10 most abundant taxa as a point plot. # In addition to colour, groups can be visualized by size and shape in point plots, # and adjusted for point size plotAbundanceDensity( tse, layout = "point", assay.type = "relabundance", n = 10, shape.by = "Geographical_location", size.by = "Age", point.size=1) # Ordering via decreasing plotAbundanceDensity( tse, assay.type = "relabundance", decreasing = FALSE) # for custom ordering set decreasing = NA and order the input object # to your wishes plotAbundanceDensity( tse, assay.type = "relabundance", decreasing = NA) # Box plots and violin plots are supported by scater::plotExpression. # Plots the relative abundance of 5 most abundant taxa as a violin plot. library(scater) top <- getTop(tse, top = 5) plotExpression(tse, features = top, assay.type = "relabundance") + ggplot2::coord_flip() # Plots the relative abundance of 5 most abundant taxa as a box plot. plotExpression(tse, features = top, assay.type = "relabundance", show_violin = FALSE, show_box = TRUE) + ggplot2::coord_flip()
data("peerj13075", package = "mia") tse <- peerj13075 # Plots the abundances of 25 most abundant taxa. Jitter plot is the default option. plotAbundanceDensity(tse, assay.type = "counts") # Counts relative abundances tse <- transformAssay(tse, method = "relabundance") # Plots the relative abundance of 10 most abundant taxa. # "nationality" information is used to color the points. X-axis is log-scaled. plotAbundanceDensity( tse, layout = "jitter", assay.type = "relabundance", n = 10, colour.by = "Geographical_location") + scale_x_log10() # Plots the relative abundance of 10 most abundant taxa as a density plot. # X-axis is log-scaled plotAbundanceDensity( tse, layout = "density", assay.type = "relabundance", n = 10 ) + scale_x_log10() # Plots the relative abundance of 10 most abundant taxa as a point plot. # Point shape is changed from default (21) to 41. plotAbundanceDensity( tse, layout = "point", assay.type = "relabundance", n = 10, point.shape = 41) # Plots the relative abundance of 10 most abundant taxa as a point plot. # In addition to colour, groups can be visualized by size and shape in point plots, # and adjusted for point size plotAbundanceDensity( tse, layout = "point", assay.type = "relabundance", n = 10, shape.by = "Geographical_location", size.by = "Age", point.size=1) # Ordering via decreasing plotAbundanceDensity( tse, assay.type = "relabundance", decreasing = FALSE) # for custom ordering set decreasing = NA and order the input object # to your wishes plotAbundanceDensity( tse, assay.type = "relabundance", decreasing = NA) # Box plots and violin plots are supported by scater::plotExpression. # Plots the relative abundance of 5 most abundant taxa as a violin plot. library(scater) top <- getTop(tse, top = 5) plotExpression(tse, features = top, assay.type = "relabundance") + ggplot2::coord_flip() # Plots the relative abundance of 5 most abundant taxa as a box plot. plotExpression(tse, features = top, assay.type = "relabundance", show_violin = FALSE, show_box = TRUE) + ggplot2::coord_flip()
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(x, ...) ## S4 method for signature 'SingleCellExperiment' plotCCA(x, dimred, ...) ## S4 method for signature 'matrix' plotCCA(x, ...) plotRDA(x, ...) ## S4 method for signature 'SingleCellExperiment' plotRDA(x, dimred, ...) ## S4 method for signature 'matrix' plotRDA(x, ...)
plotCCA(x, ...) ## S4 method for signature 'SingleCellExperiment' plotCCA(x, dimred, ...) ## S4 method for signature 'matrix' plotCCA(x, ...) plotRDA(x, ...) ## S4 method for signature 'SingleCellExperiment' plotRDA(x, dimred, ...) ## S4 method for signature 'matrix' plotRDA(x, ...)
x |
a
|
... |
additional parameters for plotting, inherited from
|
dimred |
|
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 addRDA
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
getRDA. However, the first method is recommended because it provides
the option to adjust aesthetics to the colData variables through the
arguments inherited from plotReducedDim
.
A ggplot2
object
# Load dataset library(miaViz) data("enterotype", package = "mia") tse <- enterotype # Run RDA and store results into TreeSE tse <- addRDA( tse, formula = assay ~ ClinicalStatus + Gender + Age, FUN = getDissimilarity, distance = "bray", na.action = na.exclude ) # Create RDA plot coloured by variable plotRDA(tse, "RDA", colour.by = "ClinicalStatus") # Create RDA plot with empty ellipses plotRDA(tse, "RDA", colour.by = "ClinicalStatus", add.ellipse = "colour") # Create RDA plot with text encased in labels plotRDA(tse, "RDA", colour.by = "ClinicalStatus", vec.text = FALSE) # Create RDA plot without repelling text plotRDA(tse, "RDA", colour.by = "ClinicalStatus", repel.labels = FALSE) # Create RDA plot without vectors plotRDA(tse, "RDA", colour.by = "ClinicalStatus", add.vectors = FALSE) # Calculate RDA as a separate object rda_mat <- getRDA( tse, formula = assay ~ ClinicalStatus + Gender + Age, FUN = getDissimilarity, distance = "bray", na.action = na.exclude ) # Create RDA plot from RDA matrix plotRDA(rda_mat)
# Load dataset library(miaViz) data("enterotype", package = "mia") tse <- enterotype # Run RDA and store results into TreeSE tse <- addRDA( tse, formula = assay ~ ClinicalStatus + Gender + Age, FUN = getDissimilarity, distance = "bray", na.action = na.exclude ) # Create RDA plot coloured by variable plotRDA(tse, "RDA", colour.by = "ClinicalStatus") # Create RDA plot with empty ellipses plotRDA(tse, "RDA", colour.by = "ClinicalStatus", add.ellipse = "colour") # Create RDA plot with text encased in labels plotRDA(tse, "RDA", colour.by = "ClinicalStatus", vec.text = FALSE) # Create RDA plot without repelling text plotRDA(tse, "RDA", colour.by = "ClinicalStatus", repel.labels = FALSE) # Create RDA plot without vectors plotRDA(tse, "RDA", colour.by = "ClinicalStatus", add.vectors = FALSE) # Calculate RDA as a separate object rda_mat <- getRDA( tse, formula = assay ~ ClinicalStatus + Gender + Age, FUN = getDissimilarity, distance = "bray", na.action = na.exclude ) # Create RDA plot from RDA matrix plotRDA(rda_mat)
Relative relations of two grouping can be visualized by plotting tiles with
relative sizes. plotColTile
and plotRowTile
can be used for
this.
plotColTile(object, x, y, ...) plotRowTile(object, x, y, ...) ## S4 method for signature 'SummarizedExperiment' plotColTile(object, x, y, ...) ## S4 method for signature 'SummarizedExperiment' plotRowTile(object, x, y, ...)
plotColTile(object, x, y, ...) plotRowTile(object, x, y, ...) ## S4 method for signature 'SummarizedExperiment' plotColTile(object, x, y, ...) ## S4 method for signature 'SummarizedExperiment' plotRowTile(object, x, y, ...)
object |
a
|
x |
|
y |
|
... |
additional arguments for plotting. See
|
A ggplot2
object or plotly
object, if more than one
prevalences
was defined.
data(GlobalPatterns) se <- GlobalPatterns plotColTile(se,"SampleType","Primer")
data(GlobalPatterns) se <- GlobalPatterns plotColTile(se,"SampleType","Primer")
To plot DMN fits generated with mia
use plotDMNFit
.
plotDMNFit(x, name = "DMN", type = c("laplace", "AIC", "BIC"), ...) ## S4 method for signature 'SummarizedExperiment' plotDMNFit(x, name = "DMN", type = c("laplace", "AIC", "BIC"))
plotDMNFit(x, name = "DMN", type = c("laplace", "AIC", "BIC"), ...) ## S4 method for signature 'SummarizedExperiment' plotDMNFit(x, name = "DMN", type = c("laplace", "AIC", "BIC"))
x |
a
|
name |
|
type |
|
... |
optional arguments not used. |
plotDMNFit
returns a ggplot2
plot.
library(mia) library(bluster) # Get dataset data("peerj13075", package = "mia") tse <- peerj13075 # Cluster the samples tse <- addCluster(tse, DmmParam(k = 1:4), name = "DMM", full = TRUE) # Plot the fit plotDMNFit(tse, name = "DMM", type = "laplace")
library(mia) library(bluster) # Get dataset data("peerj13075", package = "mia") tse <- peerj13075 # Cluster the samples tse <- addCluster(tse, DmmParam(k = 1:4), name = "DMM", full = TRUE) # Plot the fit plotDMNFit(tse, name = "DMM", type = "laplace")
SummarizedExperiment
plotGraph
plots an igraph
object with additional information
matched from a SummarizedExperiment
object for the nodes only.
Information on the edges have to provided manually.
plotColGraph(x, y, ...) plotRowGraph(x, y, ...) ## S4 method for signature 'ANY,SummarizedExperiment' plotColGraph( x, y, show.label = show_label, show_label = FALSE, add.legend = add_legend, add_legend = TRUE, layout = "kk", edge.type = edge_type, edge_type = c("fan", "link", "arc", "parallel"), edge.colour.by = edge_colour_by, edge_colour_by = NULL, edge.width.by = edge_width_by, edge_width_by = NULL, colour.by = colour_by, colour_by = NULL, shape.by = shape_by, shape_by = NULL, size.by = size_by, size_by = NULL, assay.type = by_exprs_values, by_exprs_values = "counts", other.fields = other_fields, other_fields = list(), ... ) ## S4 method for signature 'SummarizedExperiment,missing' plotColGraph(x, y, name = "graph", ...) ## S4 method for signature 'ANY,SummarizedExperiment' plotRowGraph( x, y, show.label = show_label, show_label = FALSE, add.legend = add_legend, add_legend = TRUE, layout = "kk", edge.type = edge_type, edge_type = c("fan", "link", "arc", "parallel"), edge.colour.by = edge_colour_by, edge_colour_by = NULL, edge.width.by = edge_width_by, edge_width_by = NULL, colour.by = colour_by, colour_by = NULL, shape.by = shape_by, shape_by = NULL, size.by = NULL, assay.type = by_exprs_values, by_exprs_values = "counts", other.fields = other_fields, other_fields = list(), ... ) ## S4 method for signature 'SummarizedExperiment,missing' plotRowGraph(x, y, name = "graph", ...)
plotColGraph(x, y, ...) plotRowGraph(x, y, ...) ## S4 method for signature 'ANY,SummarizedExperiment' plotColGraph( x, y, show.label = show_label, show_label = FALSE, add.legend = add_legend, add_legend = TRUE, layout = "kk", edge.type = edge_type, edge_type = c("fan", "link", "arc", "parallel"), edge.colour.by = edge_colour_by, edge_colour_by = NULL, edge.width.by = edge_width_by, edge_width_by = NULL, colour.by = colour_by, colour_by = NULL, shape.by = shape_by, shape_by = NULL, size.by = size_by, size_by = NULL, assay.type = by_exprs_values, by_exprs_values = "counts", other.fields = other_fields, other_fields = list(), ... ) ## S4 method for signature 'SummarizedExperiment,missing' plotColGraph(x, y, name = "graph", ...) ## S4 method for signature 'ANY,SummarizedExperiment' plotRowGraph( x, y, show.label = show_label, show_label = FALSE, add.legend = add_legend, add_legend = TRUE, layout = "kk", edge.type = edge_type, edge_type = c("fan", "link", "arc", "parallel"), edge.colour.by = edge_colour_by, edge_colour_by = NULL, edge.width.by = edge_width_by, edge_width_by = NULL, colour.by = colour_by, colour_by = NULL, shape.by = shape_by, shape_by = NULL, size.by = NULL, assay.type = by_exprs_values, by_exprs_values = "counts", other.fields = other_fields, other_fields = list(), ... ) ## S4 method for signature 'SummarizedExperiment,missing' plotRowGraph(x, y, name = "graph", ...)
x , y
|
a graph object and a
|
... |
additional arguments for plotting. See
|
show.label |
|
show_label |
Deprecated. Use |
add.legend |
|
add_legend |
Deprecated. Use |
layout |
|
edge.type |
|
edge_type |
Deprecated. Use |
edge.colour.by |
|
edge_colour_by |
Deprecated. Use |
edge.width.by |
|
edge_width_by |
Deprecated. Use |
colour.by |
|
colour_by |
Deprecated. Use |
shape.by |
|
shape_by |
Deprecated. Use |
size.by |
|
size_by |
Deprecated. Use |
assay.type |
|
by_exprs_values |
Deprecated. Use |
other.fields |
Additional fields to include in the node information without plotting them. |
other_fields |
Deprecated. Use |
name |
|
Internally tidygraph
and ggraph
are used. Therefore, all
graph types which can be converted by tidygraph::as_tbl_graph
can
be used.
a ggtree
plot
# data setup library(mia) data(GlobalPatterns) data(col_graph) data(row_graph) data(row_graph_order) metadata(GlobalPatterns)$col_graph <- col_graph genus <- agglomerateByRank(GlobalPatterns,"Genus",na.rm=TRUE) metadata(genus)$row_graph <- row_graph order <- agglomerateByRank(genus,"Order",na.rm=TRUE) metadata(order)$row_graph <- row_graph_order # plot a graph independently plotColGraph(col_graph, genus, colour.by = "SampleType", edge.colour.by = "weight", edge.width.by = "weight", show.label = TRUE) # plot the graph stored in the object plotColGraph(genus, name = "col_graph", colour.by = "SampleType", edge.colour.by = "weight", edge.width.by = "weight") # plot a graph independently plotRowGraph(row_graph, genus, colour.by = "Kingdom", edge.colour.by = "weight", edge.width.by = "weight") # plot the graph stored in the object plotRowGraph(genus, name = "row_graph", colour.by = "Phylum", edge.colour.by = "weight", edge.width.by = "weight") # plot a graph independently plotRowGraph(row_graph_order, order, colour.by = "Kingdom", edge.colour.by = "weight", edge.width.by = "weight") # plot the graph stored in the object and include some labels plotRowGraph(order, name = "row_graph", colour.by = "Phylum", edge.colour.by = "weight", edge.width.by = "weight", show.label = c("Sulfolobales","Spirochaetales", "Verrucomicrobiales")) # labels can also be included via selecting specific rownames of x/y plotRowGraph(order, name = "row_graph", colour.by = "Phylum", edge.colour.by = "weight", edge.width.by = "weight", show.label = c(1,10,50)) # labels can also be included via a logical vector, which has the same length # as nodes are present label_select <- rep(FALSE,nrow(order)) label_select[c(1,10,50)] <- TRUE plotRowGraph(order, name = "row_graph", colour.by = "Phylum", edge.colour.by = "weight", edge.width.by = "weight", show.label = label_select)
# data setup library(mia) data(GlobalPatterns) data(col_graph) data(row_graph) data(row_graph_order) metadata(GlobalPatterns)$col_graph <- col_graph genus <- agglomerateByRank(GlobalPatterns,"Genus",na.rm=TRUE) metadata(genus)$row_graph <- row_graph order <- agglomerateByRank(genus,"Order",na.rm=TRUE) metadata(order)$row_graph <- row_graph_order # plot a graph independently plotColGraph(col_graph, genus, colour.by = "SampleType", edge.colour.by = "weight", edge.width.by = "weight", show.label = TRUE) # plot the graph stored in the object plotColGraph(genus, name = "col_graph", colour.by = "SampleType", edge.colour.by = "weight", edge.width.by = "weight") # plot a graph independently plotRowGraph(row_graph, genus, colour.by = "Kingdom", edge.colour.by = "weight", edge.width.by = "weight") # plot the graph stored in the object plotRowGraph(genus, name = "row_graph", colour.by = "Phylum", edge.colour.by = "weight", edge.width.by = "weight") # plot a graph independently plotRowGraph(row_graph_order, order, colour.by = "Kingdom", edge.colour.by = "weight", edge.width.by = "weight") # plot the graph stored in the object and include some labels plotRowGraph(order, name = "row_graph", colour.by = "Phylum", edge.colour.by = "weight", edge.width.by = "weight", show.label = c("Sulfolobales","Spirochaetales", "Verrucomicrobiales")) # labels can also be included via selecting specific rownames of x/y plotRowGraph(order, name = "row_graph", colour.by = "Phylum", edge.colour.by = "weight", edge.width.by = "weight", show.label = c(1,10,50)) # labels can also be included via a logical vector, which has the same length # as nodes are present label_select <- rep(FALSE,nrow(order)) label_select[c(1,10,50)] <- TRUE plotRowGraph(order, name = "row_graph", colour.by = "Phylum", edge.colour.by = "weight", edge.width.by = "weight", show.label = label_select)
This function is used after performing a reduction method. If TreeSE
is given it retrieves the feature loadings matrix to plot values.
A tree from rowTree
can be added to heatmap layout.
plotLoadings(x, ...) ## S4 method for signature 'TreeSummarizedExperiment' plotLoadings( x, dimred, layout = "barplot", ncomponents = 5, tree.name = "phylo", row.var = NULL, add.tree = FALSE, ... ) ## S4 method for signature 'SingleCellExperiment' plotLoadings(x, dimred, layout = "barplot", ncomponents = 5, ...) ## S4 method for signature 'matrix' plotLoadings(x, layout = "barplot", ncomponents = 5, ...)
plotLoadings(x, ...) ## S4 method for signature 'TreeSummarizedExperiment' plotLoadings( x, dimred, layout = "barplot", ncomponents = 5, tree.name = "phylo", row.var = NULL, add.tree = FALSE, ... ) ## S4 method for signature 'SingleCellExperiment' plotLoadings(x, dimred, layout = "barplot", ncomponents = 5, ...) ## S4 method for signature 'matrix' plotLoadings(x, layout = "barplot", ncomponents = 5, ...)
x |
|
... |
additional parameters for plotting.
|
dimred |
|
layout |
|
ncomponents |
|
tree.name |
|
row.var |
|
add.tree |
|
These method visualize feature loadings of dimension reduction results.
Inspired by the plotASVcircular
method using phyloseq
.
TreeSummarizedExperiment
object is expected to have
content in reducedDim
slot calculated with standardized methods from
mia
or scater
package.
A ggplot2
object.
library(mia) library(scater) data("GlobalPatterns", package = "mia") tse <- GlobalPatterns # Calculate PCA tse <- agglomerateByPrevalence(tse, rank="Phylum", update.tree = TRUE) tse <- transformAssay(tse, method = "clr", pseudocount = 1) tse <- runPCA(tse, ncomponents = 5, assay.type = "clr") #' # Plotting feature loadings with tree plotLoadings(tse, dimred = "PCA", layout = "heatmap", add.tree = TRUE) # Plotting matrix as a barplot loadings_matrix <- attr(reducedDim(tse, "PCA"), "rotation") plotLoadings(loadings_matrix) # Plotting more features but less components plotLoadings(tse, dimred = "PCA", ncomponents = 2, n = 12) # Plotting matrix as heatmap without tree plotLoadings(loadings_matrix, layout = "heatmap") # Plot with less components plotLoadings(tse, "PCA", layout = "heatmap", ncomponents = 2)
library(mia) library(scater) data("GlobalPatterns", package = "mia") tse <- GlobalPatterns # Calculate PCA tse <- agglomerateByPrevalence(tse, rank="Phylum", update.tree = TRUE) tse <- transformAssay(tse, method = "clr", pseudocount = 1) tse <- runPCA(tse, ncomponents = 5, assay.type = "clr") #' # Plotting feature loadings with tree plotLoadings(tse, dimred = "PCA", layout = "heatmap", add.tree = TRUE) # Plotting matrix as a barplot loadings_matrix <- attr(reducedDim(tse, "PCA"), "rotation") plotLoadings(loadings_matrix) # Plotting more features but less components plotLoadings(tse, dimred = "PCA", ncomponents = 2, n = 12) # Plotting matrix as heatmap without tree plotLoadings(loadings_matrix, layout = "heatmap") # Plot with less components plotLoadings(tse, "PCA", layout = "heatmap", ncomponents = 2)
Wrapper for scater::plotReducedDim()
plotNMDS(x, ..., ncomponents = 2)
plotNMDS(x, ..., ncomponents = 2)
x |
a
|
... |
additional arguments passed to scater::plotReducedDim(). |
ncomponents |
|
plotPrevalence
and plotRowPrevalence
visualize prevalence
information.
plotPrevalence(x, ...) ## S4 method for signature 'SummarizedExperiment' plotPrevalence( x, detection = detections, detections = c(0.01, 0.1, 1, 2, 5, 10, 20), prevalence = prevalences, prevalences = seq(0.1, 1, 0.1), assay.type = assay_name, assay_name = "counts", rank = NULL, BPPARAM = BiocParallel::SerialParam(), ... ) plotPrevalentAbundance(x, ...) ## S4 method for signature 'SummarizedExperiment' plotPrevalentAbundance( x, rank = NULL, assay.type = assay_name, assay_name = "counts", colour.by = colour_by, colour_by = NULL, size.by = size_by, size_by = NULL, shape.by = shape_by, shape_by = NULL, show.label = label, label = NULL, facet.by = facet_by, facet_by = NULL, ... ) plotRowPrevalence(x, ...) ## S4 method for signature 'SummarizedExperiment' plotRowPrevalence( x, rank = NULL, assay.type = assay_name, assay_name = "counts", detection = detections, detections = c(0.01, 0.1, 1, 2, 5, 10, 20), min.prevalence = min_prevalence, min_prevalence = 0, BPPARAM = BiocParallel::SerialParam(), ... ) plotTaxaPrevalence(x, ...) ## S4 method for signature 'ANY' plotTaxaPrevalence(x, ...) plotFeaturePrevalence(x, ...) ## S4 method for signature 'ANY' plotFeaturePrevalence(x, ...)
plotPrevalence(x, ...) ## S4 method for signature 'SummarizedExperiment' plotPrevalence( x, detection = detections, detections = c(0.01, 0.1, 1, 2, 5, 10, 20), prevalence = prevalences, prevalences = seq(0.1, 1, 0.1), assay.type = assay_name, assay_name = "counts", rank = NULL, BPPARAM = BiocParallel::SerialParam(), ... ) plotPrevalentAbundance(x, ...) ## S4 method for signature 'SummarizedExperiment' plotPrevalentAbundance( x, rank = NULL, assay.type = assay_name, assay_name = "counts", colour.by = colour_by, colour_by = NULL, size.by = size_by, size_by = NULL, shape.by = shape_by, shape_by = NULL, show.label = label, label = NULL, facet.by = facet_by, facet_by = NULL, ... ) plotRowPrevalence(x, ...) ## S4 method for signature 'SummarizedExperiment' plotRowPrevalence( x, rank = NULL, assay.type = assay_name, assay_name = "counts", detection = detections, detections = c(0.01, 0.1, 1, 2, 5, 10, 20), min.prevalence = min_prevalence, min_prevalence = 0, BPPARAM = BiocParallel::SerialParam(), ... ) plotTaxaPrevalence(x, ...) ## S4 method for signature 'ANY' plotTaxaPrevalence(x, ...) plotFeaturePrevalence(x, ...) ## S4 method for signature 'ANY' plotFeaturePrevalence(x, ...)
x |
a
|
detection |
|
detections |
Deprecated. Use |
prevalence |
|
prevalences |
Deprecated. Use |
assay.type |
|
assay_name |
Deprecated. Use |
rank , ...
|
additional arguments
|
BPPARAM |
A
|
colour.by |
|
colour_by |
Deprecated. Use |
size.by |
|
size_by |
Deprecated. Use |
shape.by |
|
shape_by |
Deprecated. Use |
show.label |
|
label |
Deprecated. Use |
facet.by |
|
facet_by |
Deprecated. Use |
min.prevalence |
|
min_prevalence |
Deprecated. Use |
Whereas plotPrevalence
produces a line plot, plotRowPrevalence
returns a heatmap.
Agglomeration on different taxonomic levels is available through the
rank
argument.
To exclude certain taxa, preprocess x
to your liking, for example
with subsetting via getPrevalent
or
agglomerateByPrevalence
.
A ggplot2
object or plotly
object, if more than one
prevalence
was defined.
getPrevalence
,
agglomerateByPrevalence
,
agglomerateByRank
data(GlobalPatterns, package = "mia") # Apply relative transformation GlobalPatterns <- transformAssay(GlobalPatterns, method = "relabundance") # plotting N of prevalence exceeding taxa on the Phylum level plotPrevalence(GlobalPatterns, rank = "Phylum") plotPrevalence(GlobalPatterns, rank = "Phylum") + scale_x_log10() # plotting prevalence per taxa for different detection thresholds as heatmap plotRowPrevalence(GlobalPatterns, rank = "Phylum") # by default a continuous scale is used for different detection levels, # but this can be adjusted plotRowPrevalence( GlobalPatterns, rank = "Phylum", assay.type = "relabundance", detection = c(0, 0.001, 0.01, 0.1, 0.2)) # point layout for plotRowPrevalence can be used to visualize by additional # information plotPrevalentAbundance( GlobalPatterns, rank = "Family", colour.by = "Phylum") + scale_x_log10() # When using function plotPrevalentAbundace, it is possible to create facets # with 'facet.by'. plotPrevalentAbundance( GlobalPatterns, rank = "Family", colour.by = "Phylum", facet.by = "Kingdom") + scale_x_log10()
data(GlobalPatterns, package = "mia") # Apply relative transformation GlobalPatterns <- transformAssay(GlobalPatterns, method = "relabundance") # plotting N of prevalence exceeding taxa on the Phylum level plotPrevalence(GlobalPatterns, rank = "Phylum") plotPrevalence(GlobalPatterns, rank = "Phylum") + scale_x_log10() # plotting prevalence per taxa for different detection thresholds as heatmap plotRowPrevalence(GlobalPatterns, rank = "Phylum") # by default a continuous scale is used for different detection levels, # but this can be adjusted plotRowPrevalence( GlobalPatterns, rank = "Phylum", assay.type = "relabundance", detection = c(0, 0.001, 0.01, 0.1, 0.2)) # point layout for plotRowPrevalence can be used to visualize by additional # information plotPrevalentAbundance( GlobalPatterns, rank = "Family", colour.by = "Phylum") + scale_x_log10() # When using function plotPrevalentAbundace, it is possible to create facets # with 'facet.by'. plotPrevalentAbundance( GlobalPatterns, rank = "Family", colour.by = "Phylum", facet.by = "Kingdom") + scale_x_log10()
This function plots series data.
plotSeries( object, x, y = NULL, rank = NULL, colour.by = colour_by, colour_by = NULL, size.by = size_by, size_by = NULL, linetype.by = linetype_by, linetype_by = NULL, assay.type = assay_name, assay_name = "counts", ... ) ## S4 method for signature 'SummarizedExperiment' plotSeries( object, x, y = NULL, rank = NULL, colour.by = colour_by, colour_by = NULL, size.by = size_by, size_by = NULL, linetype.by = linetype_by, linetype_by = NULL, assay.type = assay_name, assay_name = "counts", ... )
plotSeries( object, x, y = NULL, rank = NULL, colour.by = colour_by, colour_by = NULL, size.by = size_by, size_by = NULL, linetype.by = linetype_by, linetype_by = NULL, assay.type = assay_name, assay_name = "counts", ... ) ## S4 method for signature 'SummarizedExperiment' plotSeries( object, x, y = NULL, rank = NULL, colour.by = colour_by, colour_by = NULL, size.by = size_by, size_by = NULL, linetype.by = linetype_by, linetype_by = NULL, assay.type = assay_name, assay_name = "counts", ... )
object |
a
|
x |
|
y |
|
rank |
|
colour.by |
|
colour_by |
Deprecated. Use |
size.by |
|
size_by |
Deprecated. Use |
linetype.by |
|
linetype_by |
Deprecated. Use |
assay.type |
|
assay_name |
Deprecated. Use |
... |
additional parameters for plotting. See
|
This function creates series plot, where x-axis includes e.g. time points, and y-axis abundances of selected taxa.
A ggplot2
object
Leo Lahti and Tuomas Borman. Contact: microbiome.github.io
## Not run: library(mia) # Load data from miaTime package library("miaTime") data(SilvermanAGutData) object <- SilvermanAGutData # Plots 2 most abundant taxa, which are colored by their family plotSeries(object, x = "DAY_ORDER", y = getTop(object, 2), colour.by = "Family") # Counts relative abundances object <- transformAssay(object, method = "relabundance") # Selects taxa taxa <- c("seq_1", "seq_2", "seq_3", "seq_4", "seq_5") # Plots relative abundances of phylums plotSeries(object[taxa,], x = "DAY_ORDER", colour.by = "Family", linetype.by = "Phylum", assay.type = "relabundance") # In addition to 'colour.by' and 'linetype.by', 'size.by' can also be used to group taxa. plotSeries(object, x = "DAY_ORDER", y = getTop(object, 5), colour.by = "Family", size.by = "Phylum", assay.type = "counts") ## End(Not run)
## Not run: library(mia) # Load data from miaTime package library("miaTime") data(SilvermanAGutData) object <- SilvermanAGutData # Plots 2 most abundant taxa, which are colored by their family plotSeries(object, x = "DAY_ORDER", y = getTop(object, 2), colour.by = "Family") # Counts relative abundances object <- transformAssay(object, method = "relabundance") # Selects taxa taxa <- c("seq_1", "seq_2", "seq_3", "seq_4", "seq_5") # Plots relative abundances of phylums plotSeries(object[taxa,], x = "DAY_ORDER", colour.by = "Family", linetype.by = "Phylum", assay.type = "relabundance") # In addition to 'colour.by' and 'linetype.by', 'size.by' can also be used to group taxa. plotSeries(object, x = "DAY_ORDER", y = getTop(object, 5), colour.by = "Family", size.by = "Phylum", assay.type = "counts") ## End(Not run)
Based on the stored data in a TreeSummarizedExperiment
a tree can
be plotted. From the rowData
, the assays
as well as the
colData
information can be taken for enriching the tree plots with
additional information.
plotRowTree(x, ...) plotColTree(x, ...) ## S4 method for signature 'TreeSummarizedExperiment' plotColTree( x, tree.name = tree_name, tree_name = "phylo", relabel.tree = relabel_tree, relabel_tree = FALSE, order.tree = order_tree, order_tree = FALSE, levels.rm = remove_levels, remove_levels = FALSE, show.label = show_label, show_label = FALSE, show.highlights = show_highlights, show_highlights = FALSE, show.highlight.label = show_highlight_label, show_highlight_label = FALSE, abbr.label = abbr_label, abbr_label = FALSE, add.legend = add_legend, add_legend = TRUE, layout = "circular", edge.colour.by = edge.colour.by, edge_colour_by = NULL, edge.size.by = edge_size_by, edge_size_by = NULL, tip.colour.by = tip_colour_by, tip_colour_by = NULL, tip.shape.by = tip_shape_by, tip_shape_by = NULL, tip.size.by = tip_size_by, tip_size_by = NULL, node.colour.by = node_colour_by, node_colour_by = NULL, node.shape.by = node_shape_by, node_shape_by = NULL, node.size.by = node_size_by, node_size_by = NULL, colour.highlights.by = colour_highlights_by, colour_highlights_by = NULL, assay.type = by_exprs_values, by_exprs_values = "counts", other.fields = other_fields, other_fields = list(), ... ) ## S4 method for signature 'TreeSummarizedExperiment' plotRowTree( x, tree.name = tree_name, tree_name = "phylo", relabel.tree = relabel_tree, relabel_tree = FALSE, order.tree = order_tree, order_tree = FALSE, levels.rm = remove_levels, remove_levels = FALSE, show.label = show_label, show_label = FALSE, show.highlights = show_highlights, show_highlights = FALSE, show.highlight.label = show_highlight_label, show_highlight_label = FALSE, abbr.label = abbr_label, abbr_label = FALSE, add.legend = add_legend, add_legend = TRUE, layout = "circular", edge.colour.by = edge_colour_by, edge_colour_by = NULL, edge.size.by = edge_size_by, edge_size_by = NULL, tip.colour.by = tip_colour_by, tip_colour_by = NULL, tip.shape.by = tip_shape_by, tip_shape_by = NULL, tip.size.by = tip_size_by, tip_size_by = NULL, node.colour.by = node_colour_by, node_colour_by = NULL, node.shape.by = node_shape_by, node_shape_by = NULL, node.size.by = node_size_by, node_size_by = NULL, colour.highlights.by = colour_highlights_by, colour_highlights_by = NULL, assay.type = by_exprs_values, by_exprs_values = "counts", other.fields = other_fields, other_fields = list(), ... )
plotRowTree(x, ...) plotColTree(x, ...) ## S4 method for signature 'TreeSummarizedExperiment' plotColTree( x, tree.name = tree_name, tree_name = "phylo", relabel.tree = relabel_tree, relabel_tree = FALSE, order.tree = order_tree, order_tree = FALSE, levels.rm = remove_levels, remove_levels = FALSE, show.label = show_label, show_label = FALSE, show.highlights = show_highlights, show_highlights = FALSE, show.highlight.label = show_highlight_label, show_highlight_label = FALSE, abbr.label = abbr_label, abbr_label = FALSE, add.legend = add_legend, add_legend = TRUE, layout = "circular", edge.colour.by = edge.colour.by, edge_colour_by = NULL, edge.size.by = edge_size_by, edge_size_by = NULL, tip.colour.by = tip_colour_by, tip_colour_by = NULL, tip.shape.by = tip_shape_by, tip_shape_by = NULL, tip.size.by = tip_size_by, tip_size_by = NULL, node.colour.by = node_colour_by, node_colour_by = NULL, node.shape.by = node_shape_by, node_shape_by = NULL, node.size.by = node_size_by, node_size_by = NULL, colour.highlights.by = colour_highlights_by, colour_highlights_by = NULL, assay.type = by_exprs_values, by_exprs_values = "counts", other.fields = other_fields, other_fields = list(), ... ) ## S4 method for signature 'TreeSummarizedExperiment' plotRowTree( x, tree.name = tree_name, tree_name = "phylo", relabel.tree = relabel_tree, relabel_tree = FALSE, order.tree = order_tree, order_tree = FALSE, levels.rm = remove_levels, remove_levels = FALSE, show.label = show_label, show_label = FALSE, show.highlights = show_highlights, show_highlights = FALSE, show.highlight.label = show_highlight_label, show_highlight_label = FALSE, abbr.label = abbr_label, abbr_label = FALSE, add.legend = add_legend, add_legend = TRUE, layout = "circular", edge.colour.by = edge_colour_by, edge_colour_by = NULL, edge.size.by = edge_size_by, edge_size_by = NULL, tip.colour.by = tip_colour_by, tip_colour_by = NULL, tip.shape.by = tip_shape_by, tip_shape_by = NULL, tip.size.by = tip_size_by, tip_size_by = NULL, node.colour.by = node_colour_by, node_colour_by = NULL, node.shape.by = node_shape_by, node_shape_by = NULL, node.size.by = node_size_by, node_size_by = NULL, colour.highlights.by = colour_highlights_by, colour_highlights_by = NULL, assay.type = by_exprs_values, by_exprs_values = "counts", other.fields = other_fields, other_fields = list(), ... )
x |
|
... |
additional arguments for plotting. See
|
tree.name |
|
tree_name |
Deprecated. Use |
relabel.tree |
|
relabel_tree |
Deprecated. Use |
order.tree |
|
order_tree |
Deprecated. Use |
levels.rm |
|
remove_levels |
Deprecated. Use |
show.label , show.highlights , show.highlight.label , abbr.label
|
|
show_label , show_highlights , show_highlight_label , abbr_label
|
Deprecated.
Use |
add.legend |
|
add_legend |
Deprecated. Use |
layout |
layout for the plotted tree. See
|
edge.colour.by |
|
edge_colour_by |
Deprecated. Use |
edge.size.by |
|
edge_size_by |
Deprecated. Use |
tip.colour.by |
|
tip_colour_by |
Deprecated. Use |
tip.shape.by |
|
tip_shape_by |
Deprecated. Use |
tip.size.by |
|
tip_size_by |
Deprecated. Use |
node.colour.by |
|
node_colour_by |
Deprecated. Use |
node.shape.by |
|
node_shape_by |
Deprecated. Use |
node.size.by |
|
node_size_by |
Deprecated. Use |
colour.highlights.by |
|
colour_highlights_by |
Deprecated. Use |
assay.type |
|
by_exprs_values |
Deprecated. Use |
other.fields |
|
other_fields |
Deprecated. Use |
If show.label
or show.highlight.label
have the same length
as the number of nodes, the vector will be used to relabel the nodes.
a ggtree
plot
library(scater) library(mia) # preparation of some data data(GlobalPatterns) GlobalPatterns <- agglomerateByRanks(GlobalPatterns) altExp(GlobalPatterns,"Genus") <- addPerFeatureQC(altExp(GlobalPatterns,"Genus")) rowData(altExp(GlobalPatterns,"Genus"))$log_mean <- log(rowData(altExp(GlobalPatterns,"Genus"))$mean) rowData(altExp(GlobalPatterns,"Genus"))$detected <- rowData(altExp(GlobalPatterns,"Genus"))$detected / 100 top_genus <- getTop(altExp(GlobalPatterns,"Genus"), method="mean", top=100L, assay.type="counts") # x <- altExp(GlobalPatterns,"Genus") plotRowTree(x[rownames(x) %in% top_genus,], tip.colour.by = "log_mean", tip.size.by = "detected") # plot with tip labels plotRowTree(x[rownames(x) %in% top_genus,], tip.colour.by = "log_mean", tip.size.by = "detected", show.label = TRUE) # plot with selected labels labels <- c("Genus:Providencia", "Genus:Morganella", "0.961.60") plotRowTree(x[rownames(x) %in% top_genus,], tip.colour.by = "log_mean", tip.size.by = "detected", show.label = labels, layout="rectangular") # plot with labeled edges plotRowTree(x[rownames(x) %in% top_genus,], edge.colour.by = "Phylum", tip.colour.by = "log_mean") # if edges are sized, colours might disappear depending on plotting device plotRowTree(x[rownames(x) %in% top_genus,], edge.colour.by = "Phylum", edge.size.by = "detected", tip.colour.by = "log_mean") # aggregating data over the taxonomic levels for plotting a taxonomic tree # please note that the original tree of GlobalPatterns is dropped by # unsplitByRanks altExps(GlobalPatterns) <- splitByRanks(GlobalPatterns) top_phyla <- getTop(altExp(GlobalPatterns,"Phylum"), method="mean", top=10L, assay.type="counts") altExps(GlobalPatterns) <- lapply(altExps(GlobalPatterns), addPerFeatureQC) altExps(GlobalPatterns) <- lapply(altExps(GlobalPatterns), function(y){ rowData(y)$log_mean <- log(rowData(y)$mean) rowData(y)$detected <- rowData(y)$detected / 100 y }) x <- unsplitByRanks(GlobalPatterns) x <- addHierarchyTree(x) highlights <- c("Phylum:Firmicutes","Phylum:Bacteroidetes", "Family:Pseudomonadaceae","Order:Bifidobacteriales") plotRowTree(x[rowData(x)$Phylum %in% top_phyla,], tip.colour.by = "log_mean", node.colour.by = "log_mean", show.highlights = highlights, show.highlight.label = highlights, colour.highlights.by = "Phylum") plotRowTree(x[rowData(x)$Phylum %in% top_phyla,], edge.colour.by = "Phylum", edge.size.by = "detected", tip.colour.by = "log_mean", node.colour.by = "log_mean")
library(scater) library(mia) # preparation of some data data(GlobalPatterns) GlobalPatterns <- agglomerateByRanks(GlobalPatterns) altExp(GlobalPatterns,"Genus") <- addPerFeatureQC(altExp(GlobalPatterns,"Genus")) rowData(altExp(GlobalPatterns,"Genus"))$log_mean <- log(rowData(altExp(GlobalPatterns,"Genus"))$mean) rowData(altExp(GlobalPatterns,"Genus"))$detected <- rowData(altExp(GlobalPatterns,"Genus"))$detected / 100 top_genus <- getTop(altExp(GlobalPatterns,"Genus"), method="mean", top=100L, assay.type="counts") # x <- altExp(GlobalPatterns,"Genus") plotRowTree(x[rownames(x) %in% top_genus,], tip.colour.by = "log_mean", tip.size.by = "detected") # plot with tip labels plotRowTree(x[rownames(x) %in% top_genus,], tip.colour.by = "log_mean", tip.size.by = "detected", show.label = TRUE) # plot with selected labels labels <- c("Genus:Providencia", "Genus:Morganella", "0.961.60") plotRowTree(x[rownames(x) %in% top_genus,], tip.colour.by = "log_mean", tip.size.by = "detected", show.label = labels, layout="rectangular") # plot with labeled edges plotRowTree(x[rownames(x) %in% top_genus,], edge.colour.by = "Phylum", tip.colour.by = "log_mean") # if edges are sized, colours might disappear depending on plotting device plotRowTree(x[rownames(x) %in% top_genus,], edge.colour.by = "Phylum", edge.size.by = "detected", tip.colour.by = "log_mean") # aggregating data over the taxonomic levels for plotting a taxonomic tree # please note that the original tree of GlobalPatterns is dropped by # unsplitByRanks altExps(GlobalPatterns) <- splitByRanks(GlobalPatterns) top_phyla <- getTop(altExp(GlobalPatterns,"Phylum"), method="mean", top=10L, assay.type="counts") altExps(GlobalPatterns) <- lapply(altExps(GlobalPatterns), addPerFeatureQC) altExps(GlobalPatterns) <- lapply(altExps(GlobalPatterns), function(y){ rowData(y)$log_mean <- log(rowData(y)$mean) rowData(y)$detected <- rowData(y)$detected / 100 y }) x <- unsplitByRanks(GlobalPatterns) x <- addHierarchyTree(x) highlights <- c("Phylum:Firmicutes","Phylum:Bacteroidetes", "Family:Pseudomonadaceae","Order:Bifidobacteriales") plotRowTree(x[rowData(x)$Phylum %in% top_phyla,], tip.colour.by = "log_mean", node.colour.by = "log_mean", show.highlights = highlights, show.highlight.label = highlights, colour.highlights.by = "Phylum") plotRowTree(x[rowData(x)$Phylum %in% top_phyla,], edge.colour.by = "Phylum", edge.size.by = "detected", tip.colour.by = "log_mean", node.colour.by = "log_mean")
TreeSummarizedExperiment
To facilitate the dressing of the tree data stored in a
TreeSummarizedExperiment
object, rowTreeData
and
colTreeData
can be used.
rowTreeData(x, ...) colTreeData(x, ...) rowTreeData(x, tree.name = tree_name, tree_name = "phylo") <- value colTreeData(x, tree.name = tree_name, tree_name = "phylo") <- value combineTreeData(x, other.fields = other_fields, other_fields = list()) combineTreeData(x, other.fields = other_fields, other_fields = list()) ## S4 method for signature 'TreeSummarizedExperiment' colTreeData(x, tree.name = tree_name, tree_name = "phylo") ## S4 method for signature 'TreeSummarizedExperiment' rowTreeData(x, tree.name = tree_name, tree_name = "phylo") ## S4 replacement method for signature 'TreeSummarizedExperiment' colTreeData(x, tree.name = tree_name, tree_name = "phylo") <- value ## S4 replacement method for signature 'TreeSummarizedExperiment' rowTreeData(x, tree.name = tree_name, tree_name = "phylo") <- value ## S4 method for signature 'phylo' combineTreeData(x, other.fields = other_fields, other_fields = list()) ## S4 method for signature 'treedata' combineTreeData(x, other.fields = other_fields, other_fields = list())
rowTreeData(x, ...) colTreeData(x, ...) rowTreeData(x, tree.name = tree_name, tree_name = "phylo") <- value colTreeData(x, tree.name = tree_name, tree_name = "phylo") <- value combineTreeData(x, other.fields = other_fields, other_fields = list()) combineTreeData(x, other.fields = other_fields, other_fields = list()) ## S4 method for signature 'TreeSummarizedExperiment' colTreeData(x, tree.name = tree_name, tree_name = "phylo") ## S4 method for signature 'TreeSummarizedExperiment' rowTreeData(x, tree.name = tree_name, tree_name = "phylo") ## S4 replacement method for signature 'TreeSummarizedExperiment' colTreeData(x, tree.name = tree_name, tree_name = "phylo") <- value ## S4 replacement method for signature 'TreeSummarizedExperiment' rowTreeData(x, tree.name = tree_name, tree_name = "phylo") <- value ## S4 method for signature 'phylo' combineTreeData(x, other.fields = other_fields, other_fields = list()) ## S4 method for signature 'treedata' combineTreeData(x, other.fields = other_fields, other_fields = list())
x |
a
|
... |
additional arguments, currently not used. |
tree.name |
|
tree_name |
Deprecated. Use |
other.fields , value
|
a |
other_fields |
Deprecated. Use |
To match information to nodes, the id information in other.fields
are used.
These can either be a column, named ‘node’ or ‘label’
(‘node’ taking precedent), or rownames. If all rownames can be coerced
to integer
, they are considered as ‘node’ values, otherwise as
‘label’ values. The id information must be unique and match available
values of rowTreeData(c)
The result of the accessors, rowTreeData
and colTreeData
,
contain at least a ‘node’ and ‘label’ column.
a data.frame
for the accessor and the modified
TreeSummarizedExperiment
object
data(GlobalPatterns) td <- rowTreeData(GlobalPatterns) td td$test <- rnorm(nrow(td)) rowTreeData(GlobalPatterns) <- td rowTreeData(GlobalPatterns) combineTreeData(rowTree(GlobalPatterns), td)
data(GlobalPatterns) td <- rowTreeData(GlobalPatterns) td td$test <- rnorm(nrow(td)) rowTreeData(GlobalPatterns) <- td rowTreeData(GlobalPatterns) combineTreeData(rowTree(GlobalPatterns), td)