Contents

miaViz implements plotting function to work with TreeSummarizedExperiment and related objects in a context of microbiome analysis. For more general plotting function on SummarizedExperiment objects the scater package offers several options, such as plotColData, plotExpression and plotRowData.

1 Installation

To install miaViz, install BiocManager first, if it is not installed. Afterwards use the install function from BiocManager and load miaViz.

if (!requireNamespace("BiocManager", quietly = TRUE))
    install.packages("BiocManager")

BiocManager::install("miaViz")
#> Bioconductor version 3.13 (BiocManager 1.30.16), R 4.1.0 (2021-05-18)
#> Warning: package(s) not installed when version(s) same as current; use `force = TRUE` to
#>   re-install: 'miaViz'
library(miaViz)
data(GlobalPatterns, package = "mia")

2 Abundance plotting

in contrast to other fields of sequencing based fields of research for which expression of genes is usually studied, microbiome research uses the more term Abundance to described the numeric data measured and analyzed. Technically, especially in context of SummarizedExperiment objects, there is no difference. Therefore plotExpression can be used to plot Abundance data.

plotAbundance can be used as well and as long as rank is set NULL, it behaves as plotExpression.

plotAbundance(GlobalPatterns, rank = NULL, 
              features = "549322", abund_values = "counts")

However, if the rank is set not NULL a bar plot is returned. At the same time the features argument can be set to NULL (default).

GlobalPatterns <- transformCounts(GlobalPatterns, method = "relabundance")
plotAbundance(GlobalPatterns, rank = "Kingdom", abund_values = "relabundance")

With subsetting to selected features the plot can be fine tuned.

prev_phylum <- getPrevalentTaxa(GlobalPatterns, rank = "Phylum",
                                detection = 0.01)
plotAbundance(GlobalPatterns[rowData(GlobalPatterns)$Phylum %in% prev_phylum],
              rank = "Phylum",
              abund_values = "relabundance")

The features argument is reused for plotting data along the different samples. In the next example the SampleType is plotted along the samples. In this case the result is a list, which can combined using external tools, for example patchwork.

library(patchwork)
plots <- plotAbundance(GlobalPatterns[rowData(GlobalPatterns)$Phylum %in% prev_phylum],
                       features = "SampleType",
                       rank = "Phylum",
                       abund_values = "relabundance")
plots$abundance / plots$SampleType +
     plot_layout(heights = c(9, 1))

3 Prevalence plotting

To visualize prevalence within the dataset, two functions are available, plotTaxaPrevalence, plotPrevalenceAbundance and plotPrevalence.

plotTaxaPrevalence produces a so-called landscape plot, which visualizes the prevalence of samples across abundance thresholds.

plotTaxaPrevalence(GlobalPatterns, rank = "Phylum",
                   detections = c(0, 0.001, 0.01, 0.1, 0.2))

plotPrevalenceAbundance plot the prevalence depending on the mean relative abundance on the chosen taxonomic level.

plotPrevalentAbundance(GlobalPatterns, rank = "Family",
                       colour_by = "Phylum") +
    scale_x_log10()

plotPrevalence plot the number of samples and their prevalence across different abundance thresholds. Abundance steps can be adjusted using the detections argument, whereas the analyzed prevalence steps is set using the prevalences argument.

plotPrevalence(GlobalPatterns,
               rank = "Phylum",
               detections = c(0.01, 0.1, 1, 2, 5, 10, 20)/100,
               prevalences = seq(0.1, 1, 0.1))

4 Tree plotting

The information stored in the rowTree can be directly plotted. However, sizes of stored trees have to be kept in mind and plotting of large trees rarely makes sense.

For this example we limit the information plotted to the top 100 taxa as judged by mean abundance on the genus level.

library(scater)
library(mia)
altExp(GlobalPatterns,"Genus") <- agglomerateByRank(GlobalPatterns,"Genus")
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_taxa <- getTopTaxa(altExp(GlobalPatterns,"Genus"),
                       method="mean",
                       top=100L,
                       abund_values="counts")

Colour, size and shape of tree tips and nodes can be decorated based on data present in the SE object or by providing additional information via the other_fields argument. Note that currently information for nodes have to be provided via the other_fields arguments.

Data will be matched via the node or label argument depending on which was provided. label takes precedent.

plotRowTree(altExp(GlobalPatterns,"Genus")[top_taxa,],
            tip_colour_by = "log_mean",
            tip_size_by = "detected")
#> Warning in .numeric_ij(ij = i, x = x, dim = "row"): For rows/cols with the same
#> name, only one is output
#> Warning in convertNode(tree = track, node = oldAlias): Multiple nodes are found
#> to have the same label.
#> Warning in convertNode(tree = value, node = nlk$nodeLab[iRep]): Multiple nodes
#> are found to have the same label.
Tree plot using ggtree with tip labels decorated by mean abundance (colour) and prevalence (size)

Figure 1: Tree plot using ggtree with tip labels decorated by mean abundance (colour) and prevalence (size)

Tip and node labels can be shown as well. Setting show_label = TRUE shows the tip labels only …

plotRowTree(altExp(GlobalPatterns,"Genus")[top_taxa,],
            tip_colour_by = "log_mean",
            tip_size_by = "detected",
            show_label = TRUE)
#> Warning in .numeric_ij(ij = i, x = x, dim = "row"): For rows/cols with the same
#> name, only one is output
#> Warning in convertNode(tree = track, node = oldAlias): Multiple nodes are found
#> to have the same label.
#> Warning in convertNode(tree = value, node = nlk$nodeLab[iRep]): Multiple nodes
#> are found to have the same label.
Tree plot using ggtree with tip labels decorated by mean abundance (colour) and prevalence (size). Tip labels of the tree are shown as well.

Figure 2: Tree plot using ggtree with tip labels decorated by mean abundance (colour) and prevalence (size)
Tip labels of the tree are shown as well.

… whereas node labels can be selectively shown by providing a named logical vector to show_label.

Please not that currently ggtree only can plot node labels in a rectangular layout.

labels <- c("Genus:Providencia", "Genus:Morganella", "0.961.60")
plotRowTree(altExp(GlobalPatterns,"Genus")[top_taxa,],
            tip_colour_by = "log_mean",
            tip_size_by = "detected",
            show_label = labels,
            layout="rectangular")
#> Warning in .numeric_ij(ij = i, x = x, dim = "row"): For rows/cols with the same
#> name, only one is output
#> Warning in convertNode(tree = track, node = oldAlias): Multiple nodes are found
#> to have the same label.
#> Warning in convertNode(tree = value, node = nlk$nodeLab[iRep]): Multiple nodes
#> are found to have the same label.
Tree plot using ggtree with tip labels decorated by mean abundance (colour) and prevalence (size). Selected node and tip labels are shown.

Figure 3: Tree plot using ggtree with tip labels decorated by mean abundance (colour) and prevalence (size)
Selected node and tip labels are shown.

Information can also be visualized on the edges of the tree plot.

plotRowTree(altExp(GlobalPatterns,"Genus")[top_taxa,],
            edge_colour_by = "Phylum",
            tip_colour_by = "log_mean")
#> Warning in .numeric_ij(ij = i, x = x, dim = "row"): For rows/cols with the same
#> name, only one is output
#> Warning in convertNode(tree = track, node = oldAlias): Multiple nodes are found
#> to have the same label.
#> Warning in convertNode(tree = value, node = nlk$nodeLab[iRep]): Multiple nodes
#> are found to have the same label.
Tree plot using ggtree with tip labels decorated by mean abundance (colour) and edges labeled Kingdom (colour) and prevalence (size)

Figure 4: Tree plot using ggtree with tip labels decorated by mean abundance (colour) and edges labeled Kingdom (colour) and prevalence (size)

5 Graph plotting

Similar to tree data, graph data can also be plotted in conjunction with SummarizedExperiment objects. Since the graph data in itself cannot be stored in a specialized slot, a graph object can be provided separately or as an element from the metedata.

Here we load an example graph. As graph data, all objects types accepted by as_tbl_graph from the tidygraph package are supported.

data(col_graph)

In the following examples, the weight data is automatically generated from the graph data. The SummarizedExperiment provided is required to have overlapping rownames with the node names of the graph. Using this link the graph plot can incorporated data from the SummarizedExperiment.

plotColGraph(col_graph,
             altExp(GlobalPatterns,"Genus"),
             colour_by = "SampleType",
             edge_colour_by = "weight",
             edge_width_by = "weight",
             show_label = TRUE)

As mentioned the graph data can be provided from the metadata of the SummarizedExperiment.

metadata(altExp(GlobalPatterns,"Genus"))$graph <- col_graph

This produces the same plot as shown above.

6 Plotting of serial data

library(microbiomeDataSets)
#> Loading required package: MultiAssayExperiment
silverman <- SilvermanAGutData()
#> snapshotDate(): 2021-05-18
#> see ?microbiomeDataSets and browseVignettes('microbiomeDataSets') for documentation
#> loading from cache
#> see ?microbiomeDataSets and browseVignettes('microbiomeDataSets') for documentation
#> loading from cache
#> see ?microbiomeDataSets and browseVignettes('microbiomeDataSets') for documentation
#> loading from cache
#> see ?microbiomeDataSets and browseVignettes('microbiomeDataSets') for documentation
#> loading from cache
#> see ?microbiomeDataSets and browseVignettes('microbiomeDataSets') for documentation
#> loading from cache
silverman <- transformCounts(silverman, method = "relabundance")
taxa <- getTopTaxa(silverman, 2)

Data from samples collected along time can be visualized using plotSeries. The x argument is used to reference data from the colData to use as descriptor for ordering the data. The y argument selects the feature to show. Since plotting a lot of features is not advised a maximum of 20 features can plotted at the same time.

plotSeries(silverman,
           x = "DAY_ORDER",
           y = taxa,
           colour_by = "Family")

If replicated data is present, data is automatically used for calculation of the mean and sd and plotted as a range. Data from different assays can be used for plotting via the abund_values.

plotSeries(silverman[taxa,],
           x = "DAY_ORDER",
           colour_by = "Family",
           linetype_by = "Phylum",
           abund_values = "relabundance")

Additional variables can be used to modify line type aesthetics.

plotSeries(silverman,
           x = "DAY_ORDER",
           y = getTopTaxa(silverman, 5),
           colour_by = "Family",
           linetype_by = "Phylum",
           abund_values = "counts")

7 Session info

sessionInfo()
#> R version 4.1.0 (2021-05-18)
#> Platform: x86_64-pc-linux-gnu (64-bit)
#> Running under: Ubuntu 20.04.2 LTS
#> 
#> Matrix products: default
#> BLAS:   /home/biocbuild/bbs-3.13-bioc/R/lib/libRblas.so
#> LAPACK: /home/biocbuild/bbs-3.13-bioc/R/lib/libRlapack.so
#> 
#> locale:
#>  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
#>  [3] LC_TIME=en_GB              LC_COLLATE=C              
#>  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
#>  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
#>  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
#> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
#> 
#> attached base packages:
#> [1] parallel  stats4    stats     graphics  grDevices utils     datasets 
#> [8] methods   base     
#> 
#> other attached packages:
#>  [1] microbiomeDataSets_1.0.0       MultiAssayExperiment_1.18.0   
#>  [3] scater_1.20.1                  scuttle_1.2.0                 
#>  [5] patchwork_1.1.1                miaViz_1.0.1                  
#>  [7] ggraph_2.0.5                   ggplot2_3.3.5                 
#>  [9] mia_1.0.5                      TreeSummarizedExperiment_2.0.2
#> [11] Biostrings_2.60.1              XVector_0.32.0                
#> [13] SingleCellExperiment_1.14.1    SummarizedExperiment_1.22.0   
#> [15] Biobase_2.52.0                 GenomicRanges_1.44.0          
#> [17] GenomeInfoDb_1.28.0            IRanges_2.26.0                
#> [19] S4Vectors_0.30.0               BiocGenerics_0.38.0           
#> [21] MatrixGenerics_1.4.0           matrixStats_0.59.0            
#> [23] BiocStyle_2.20.2              
#> 
#> loaded via a namespace (and not attached):
#>   [1] AnnotationHub_3.0.1           BiocFileCache_2.0.0          
#>   [3] plyr_1.8.6                    igraph_1.2.6                 
#>   [5] lazyeval_0.2.2                splines_4.1.0                
#>   [7] BiocParallel_1.26.0           digest_0.6.27                
#>   [9] htmltools_0.5.1.1             viridis_0.6.1                
#>  [11] magick_2.7.2                  fansi_0.5.0                  
#>  [13] magrittr_2.0.1                memoise_2.0.0                
#>  [15] ScaledMatrix_1.0.0            cluster_2.1.2                
#>  [17] DECIPHER_2.20.0               graphlayouts_0.7.1           
#>  [19] colorspace_2.0-2              rappdirs_0.3.3               
#>  [21] blob_1.2.1                    ggrepel_0.9.1                
#>  [23] xfun_0.24                     dplyr_1.0.7                  
#>  [25] crayon_1.4.1                  RCurl_1.98-1.3               
#>  [27] jsonlite_1.7.2                ape_5.5                      
#>  [29] glue_1.4.2                    polyclip_1.10-0              
#>  [31] gtable_0.3.0                  zlibbioc_1.38.0              
#>  [33] DelayedArray_0.18.0           BiocSingular_1.8.1           
#>  [35] scales_1.1.1                  DBI_1.1.1                    
#>  [37] Rcpp_1.0.6                    xtable_1.8-4                 
#>  [39] viridisLite_0.4.0             decontam_1.12.0              
#>  [41] tidytree_0.3.4                bit_4.0.4                    
#>  [43] rsvd_1.0.5                    httr_1.4.2                   
#>  [45] RColorBrewer_1.1-2            ellipsis_0.3.2               
#>  [47] pkgconfig_2.0.3               farver_2.1.0                 
#>  [49] sass_0.4.0                    dbplyr_2.1.1                 
#>  [51] utf8_1.2.1                    AnnotationDbi_1.54.1         
#>  [53] later_1.2.0                   tidyselect_1.1.1             
#>  [55] labeling_0.4.2                rlang_0.4.11                 
#>  [57] reshape2_1.4.4                munsell_0.5.0                
#>  [59] BiocVersion_3.13.1            tools_4.1.0                  
#>  [61] cachem_1.0.5                  DirichletMultinomial_1.34.0  
#>  [63] generics_0.1.0                RSQLite_2.2.7                
#>  [65] ExperimentHub_2.0.0           evaluate_0.14                
#>  [67] stringr_1.4.0                 fastmap_1.1.0                
#>  [69] yaml_2.2.1                    ggtree_3.0.2                 
#>  [71] knitr_1.33                    bit64_4.0.5                  
#>  [73] tidygraph_1.2.0               purrr_0.3.4                  
#>  [75] KEGGREST_1.32.0               nlme_3.1-152                 
#>  [77] sparseMatrixStats_1.4.0       mime_0.11                    
#>  [79] aplot_0.0.6                   compiler_4.1.0               
#>  [81] png_0.1-7                     interactiveDisplayBase_1.30.0
#>  [83] filelock_1.0.2                curl_4.3.2                   
#>  [85] beeswarm_0.4.0                treeio_1.16.1                
#>  [87] tibble_3.1.2                  tweenr_1.0.2                 
#>  [89] bslib_0.2.5.1                 stringi_1.6.2                
#>  [91] highr_0.9                     lattice_0.20-44              
#>  [93] Matrix_1.3-4                  vegan_2.5-7                  
#>  [95] permute_0.9-5                 vctrs_0.3.8                  
#>  [97] pillar_1.6.1                  lifecycle_1.0.0              
#>  [99] BiocManager_1.30.16           jquerylib_0.1.4              
#> [101] BiocNeighbors_1.10.0          cowplot_1.1.1                
#> [103] bitops_1.0-7                  irlba_2.3.3                  
#> [105] httpuv_1.6.1                  R6_2.5.0                     
#> [107] promises_1.2.0.1              bookdown_0.22                
#> [109] gridExtra_2.3                 vipor_0.4.5                  
#> [111] MASS_7.3-54                   assertthat_0.2.1             
#> [113] withr_2.4.2                   GenomeInfoDbData_1.2.6       
#> [115] mgcv_1.8-36                   grid_4.1.0                   
#> [117] beachmat_2.8.0                tidyr_1.1.3                  
#> [119] rmarkdown_2.9                 DelayedMatrixStats_1.14.0    
#> [121] rvcheck_0.1.8                 ggnewscale_0.4.5             
#> [123] ggforce_0.3.3                 shiny_1.6.0                  
#> [125] ggbeeswarm_0.6.0

8 References