phylobar is a visualization package for constructing stacked barplots by interactively “painting” an associated tree. This is an alternative to defining a color palette at a fixed taxonomic resolution. It also helps avoid the issue of grouping all rare taxa into a color for “other” — you can selectively highlight specific rare taxa while leaving others at their background color.
The main function, phylobar(), takes two inputs: a table of (potentially
normalized) counts and a tree structure which can come from either a phylogeny
or a table of taxonomic assignments. phylobar is designed for submission to
Bioconductor and is compatible with popular
Bioconductor containers such as
TreeSummarizedExperiment
and phyloseq, so the
visualization works seamlessly with a wide range of existing datasets. Several
vignettes — including Global Patterns,
Diet Analysis, Taxonomies, and
Atlas — demonstrate working with data from these containers. You
can read more about the package in our preprint:
Kuo, M., Lê Cao, K.-A., Kodikara, S., Mao, J., & Sankaran, K. (2025). phylobar: an R package for multiresolution compositional barplots in omics studies. doi:10.1101/2025.11.05.686662
You can install phylobar from Bioconductor using:
if (!require("BiocManager", quietly = TRUE))
install.packages("BiocManager")
BiocManager::install("phylobar")
Alternatively, you can install the development version from GitHub:
remotes::install_github("mkdiro-o/phylobar")
The block below applies phylobar to a small random dataset. Click a node to collapse a subtree, press the Control key to add a new color, and press the Escape key to freeze the view.
library(ape)
library(phylobar)
tree <- rtree(20)
samples <- matrix(rpois(100 * 20, 1), 100, 20)
phylobar(samples, tree)
The vignettes below walk through common workflows and fully developed case studies. They are grouped into workflow vignettes (how to prepare, style, and export phylobar plots) and case-study vignettes (biological analyses that illustrate phylobar in practice).
Rather than interacting with abstract phylogenetic trees, it can be helpful to
choose stacked bar colors using taxonomic assignments. This vignette gives a
comprehensive guide to converting taxonomy tables into valid phylo objects via
taxonomy_to_tree(). It covers three common pitfalls — missing root nodes,
missing assignments encoded as strings instead of NA, and duplicated names
across taxonomic levels — and shows how to resolve each with add_prefix() and
checkValidPhylo().
Phylobar supports several styling options, including custom color palettes,
widget dimensions, sample label font and margin settings, tree-bar layout ratios
(rel_width, rel_height, rel_space), legend placement, and hierarchical
reordering with hclust_order. This vignette walks through all currently
available parameters.
While interactivity is useful for exploration, we often need to export a specific static view to discuss with collaborators. This vignette shows how to export phylobar visualizations to SVG using the SVG Crowbar bookmarklet, edit the resulting layered SVG in Inkscape, and export to PNG — preserving image quality for publication.
This vignette benchmarks phylobar() across a grid of sample counts and taxa
counts, with and without hierarchical clustering. It shows that disabling
hclust_order improves performance at large sample sizes, and recommends using
subset_cluster() to keep the number of samples browser-friendly.
Analyzes 16S rRNA data from 47 mice on either normal or high-fat, high-sugar (HFHS) diets across four timepoints. The vignette reproduces known findings of decreased Bacteroidetes and increased Firmicutes under HFHS and adds a longitudinal view tracking individual mice over time.
Demonstrates phylobar on the HITChip Atlas 1006 human gut microbiome dataset,
highlighting “tipping element” taxa and the Firmicutes/Bacteroidetes balance. It
also shows how subset_cluster() can reduce visual clutter by selecting
representative samples.
Examines how diet shapes gut microbiome composition using the dietswap dataset.
It applies DESeq2 normalization via MicrobiomeStat, builds a taxonomy tree, and
visualizes the resulting abundances with phylobar.
Shows how to create phylobar plots from both phyloseq and
TreeSummarizedExperiment input objects using the Global Patterns dataset,
demonstrating that both container formats work interchangeably.
Applies phylobar to immune cell-type compositions from COVID-19 patient data, using a manually defined cell-type hierarchy in place of a microbial taxonomy. This vignette illustrates phylobar’s applicability beyond microbiome studies.
The full function reference is available at https://mkdiro-o.github.io/phylobar/reference/.
You can reach us by creating an Issue or emailing ksankaran@wisc.edu. We appreciate your interest and will respond promptly.
sessionInfo()
#> R version 4.6.0 RC (2026-04-17 r89917)
#> Platform: x86_64-pc-linux-gnu
#> Running under: Ubuntu 24.04.4 LTS
#>
#> Matrix products: default
#> BLAS: /home/biocbuild/bbs-3.23-bioc/R/lib/libRblas.so
#> LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.12.0 LAPACK version 3.12.0
#>
#> 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
#>
#> time zone: America/New_York
#> tzcode source: system (glibc)
#>
#> attached base packages:
#> [1] stats4 stats graphics grDevices utils datasets methods
#> [8] base
#>
#> other attached packages:
#> [1] DESeq2_1.51.7 SummarizedExperiment_1.41.1
#> [3] Biobase_2.71.0 MatrixGenerics_1.23.0
#> [5] matrixStats_1.5.0 GenomicRanges_1.63.2
#> [7] Seqinfo_1.1.0 IRanges_2.45.0
#> [9] S4Vectors_0.49.2 BiocGenerics_0.57.1
#> [11] generics_0.1.4 zen4R_0.10.5
#> [13] seriation_1.5.8 tidyr_1.3.2
#> [15] tibble_3.3.1 readr_2.2.0
#> [17] dplyr_1.2.1 microbiome_1.33.0
#> [19] ggplot2_4.0.3 phyloseq_1.55.2
#> [21] phylobar_0.99.9 ape_5.8-1
#> [23] BiocStyle_2.39.0
#>
#> loaded via a namespace (and not attached):
#> [1] phangorn_2.12.1 permute_0.9-10 rlang_1.2.0
#> [4] magrittr_2.0.5 ade4_1.7-24 otel_0.2.0
#> [7] compiler_4.6.0 mgcv_1.9-4 vctrs_0.7.3
#> [10] reshape2_1.4.5 quadprog_1.5-8 stringr_1.6.0
#> [13] pkgconfig_2.0.3 crayon_1.5.3 fastmap_1.2.0
#> [16] XVector_0.51.0 ca_0.71.1 utf8_1.2.6
#> [19] rmarkdown_2.31 tzdb_0.5.0 bit_4.6.0
#> [22] purrr_1.2.2 xfun_0.57 cachem_1.1.0
#> [25] jsonlite_2.0.0 biomformat_1.39.17 DelayedArray_0.37.1
#> [28] BiocParallel_1.45.0 parallel_4.6.0 cluster_2.1.8.2
#> [31] R6_2.6.1 bslib_0.10.0 stringi_1.8.7
#> [34] RColorBrewer_1.1-3 jquerylib_0.1.4 Rcpp_1.1.1-1.1
#> [37] bookdown_0.46 iterators_1.0.14 knitr_1.51
#> [40] Matrix_1.7-5 splines_4.6.0 igraph_2.3.0
#> [43] tidyselect_1.2.1 dichromat_2.0-0.1 abind_1.4-8
#> [46] yaml_2.3.12 vegan_2.7-3 TSP_1.2.7
#> [49] codetools_0.2-20 curl_7.1.0 lattice_0.22-9
#> [52] plyr_1.8.9 withr_3.0.2 S7_0.2.2
#> [55] evaluate_1.0.5 Rtsne_0.17 survival_3.8-6
#> [58] xml2_1.5.2 Biostrings_2.79.5 pillar_1.11.1
#> [61] BiocManager_1.30.27 foreach_1.5.2 vroom_1.7.1
#> [64] hms_1.1.4 scales_1.4.0 glue_1.8.1
#> [67] tools_4.6.0 data.table_1.18.2.1 locfit_1.5-9.12
#> [70] registry_0.5-1 XML_3.99-0.23 fastmatch_1.1-8
#> [73] grid_4.6.0 nlme_3.1-169 cli_3.6.6
#> [76] S4Arrays_1.11.1 keyring_1.4.1 gtable_0.3.6
#> [79] sass_0.4.10 digest_0.6.39 SparseArray_1.11.13
#> [82] htmlwidgets_1.6.4 farver_2.1.2 htmltools_0.5.9
#> [85] multtest_2.67.0 lifecycle_1.0.5 httr_1.4.8
#> [88] bit64_4.8.0 MASS_7.3-65