Contents

1 Overview

Phylobar draws a phylogenetic tree alongside a stacked bar chart. This vignette shows how to customize visual style: text sizes, color palettes, layout ratios, legend placement, and more.

We will use a small random dataset:

library(ape)
library(phylobar)

set.seed(1)
tree <- rtree(20)
samples <- matrix(rpois(100 * 20, 1), nrow = 100, ncol = 20)

phylobar(samples, tree)

The function signature and key styling parameters we will explore:

Internally, phylobar() ensures that the tree has node labels and that the abundance matrix has row/column names. If they’re missing, helper check_inputs() creates sensible defaults (e.g., sample_1, sample_2).

2 Color Palette

If a palette is not provided, phylobar uses a default set of six colors. It is possible to supply own vector of hex colors or R color names.

# Custom qualitative palette (as many colors as you want; repeats if needed)
my_palette <- c(
    "#4E79A7", "#F28E2B", "#E15759",
    "#76B7B2", "#59A14F", "#EDC948"
)
phylobar(samples, tree, palette = my_palette)

3 Widget Size

By default the widget adapts to the container. Fix its size by:

phylobar(samples, tree,
    width = 800,
    height = 500
)

4 Sample Label Styling

Control sample label font size, spacing, and hover magnification.

phylobar(samples, tree,
    width = 800, height = 500,
    sample_font_size = 10,
    sample_label_margin = 10, # space between labels and bars
    sample_label_space = 100, # reserved margin for labels
    sample_magnify = 1.3, # how much to enlarge labels on hover
    sample_show_all = TRUE
)

5 Tree-bar Layout Ratio

Change how much horizontal and vertical space the tree occupies:

phylobar(
    samples, tree,
    width = 800, height = 500,
    sample_label_space = 100,
    sample_magnify = 1.3,
    rel_width = 0.2, # narrower tree
    rel_height = 0.70, # shorter tree (more space for legend)
    rel_space = 14 # larger gap between panels
)

6 Legend Placement

Choose whether painted subtree labels appear in a separate legend (legend_mode = TRUE, default) or placed inside the tree (legend_mode = FALSE). legend_x_start and legend_spacing can also be adjusted to control the legen position.

# Legend below the tree (default)
phylobar(
    samples, tree,
    width = 800, height = 500,
    sample_label_space = 100,
    sample_magnify = 1.3,
    legend_mode = TRUE,
    legend_x_start = 20, # horizontal start in pixels
    legend_spacing = 20 # vertical spacing between legend items in pixels
)
# Put labels inside the tree instead of a separate legend
phylobar(
    samples, tree,
    width = 800, height = 500,
    sample_label_space = 100,
    sample_magnify = 1.3,
    legend_mode = FALSE,
    legend_x_start = 20, # horizontal start in pixels
    legend_spacing = 20 # vertical spacing between legend items in pixels
)

7 Optional Hierarchical Reordering

hclust_order = TRUE (default) reorders samples/features by hierarchical clustering, which can make patterns more visible. Turn it off to preserve original order:

# Keep the input order as-is
phylobar(
    samples, tree,
    width = 800, height = 500,
    sample_label_space = 100,
    sample_magnify = 1.3,
    hclust_order = FALSE
)

8 Session Info

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] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#>  [1] zen4R_0.10.5      seriation_1.5.8   tidyr_1.3.2       tibble_3.3.1     
#>  [5] readr_2.2.0       dplyr_1.2.1       microbiome_1.33.0 ggplot2_4.0.3    
#>  [9] phyloseq_1.55.2   phylobar_0.99.9   ape_5.8-1         BiocStyle_2.39.0 
#> 
#> loaded via a namespace (and not attached):
#>  [1] phangorn_2.12.1             permute_0.9-10             
#>  [3] rlang_1.2.0                 magrittr_2.0.5             
#>  [5] ade4_1.7-24                 otel_0.2.0                 
#>  [7] matrixStats_1.5.0           compiler_4.6.0             
#>  [9] mgcv_1.9-4                  vctrs_0.7.3                
#> [11] reshape2_1.4.5              quadprog_1.5-8             
#> [13] stringr_1.6.0               pkgconfig_2.0.3            
#> [15] crayon_1.5.3                fastmap_1.2.0              
#> [17] XVector_0.51.0              ca_0.71.1                  
#> [19] utf8_1.2.6                  rmarkdown_2.31             
#> [21] tzdb_0.5.0                  bit_4.6.0                  
#> [23] purrr_1.2.2                 xfun_0.57                  
#> [25] cachem_1.1.0                jsonlite_2.0.0             
#> [27] biomformat_1.39.17          DelayedArray_0.37.1        
#> [29] parallel_4.6.0              cluster_2.1.8.2            
#> [31] R6_2.6.1                    bslib_0.10.0               
#> [33] stringi_1.8.7               RColorBrewer_1.1-3         
#> [35] GenomicRanges_1.63.2        jquerylib_0.1.4            
#> [37] Rcpp_1.1.1-1.1              Seqinfo_1.1.0              
#> [39] bookdown_0.46               SummarizedExperiment_1.41.1
#> [41] iterators_1.0.14            knitr_1.51                 
#> [43] IRanges_2.45.0              Matrix_1.7-5               
#> [45] splines_4.6.0               igraph_2.3.0               
#> [47] tidyselect_1.2.1            dichromat_2.0-0.1          
#> [49] abind_1.4-8                 yaml_2.3.12                
#> [51] vegan_2.7-3                 TSP_1.2.7                  
#> [53] codetools_0.2-20            curl_7.1.0                 
#> [55] lattice_0.22-9              plyr_1.8.9                 
#> [57] Biobase_2.71.0              withr_3.0.2                
#> [59] S7_0.2.2                    evaluate_1.0.5             
#> [61] Rtsne_0.17                  survival_3.8-6             
#> [63] xml2_1.5.2                  Biostrings_2.79.5          
#> [65] pillar_1.11.1               BiocManager_1.30.27        
#> [67] MatrixGenerics_1.23.0       foreach_1.5.2              
#> [69] stats4_4.6.0                generics_0.1.4             
#> [71] vroom_1.7.1                 S4Vectors_0.49.2           
#> [73] hms_1.1.4                   scales_1.4.0               
#> [75] glue_1.8.1                  tools_4.6.0                
#> [77] data.table_1.18.2.1         registry_0.5-1             
#> [79] XML_3.99-0.23               fastmatch_1.1-8            
#> [81] grid_4.6.0                  nlme_3.1-169               
#> [83] cli_3.6.6                   S4Arrays_1.11.1            
#> [85] keyring_1.4.1               gtable_0.3.6               
#> [87] sass_0.4.10                 digest_0.6.39              
#> [89] BiocGenerics_0.57.1         SparseArray_1.11.13        
#> [91] htmlwidgets_1.6.4           farver_2.1.2               
#> [93] htmltools_0.5.9             multtest_2.67.0            
#> [95] lifecycle_1.0.5             httr_1.4.8                 
#> [97] bit64_4.8.0                 MASS_7.3-65