# Working with phyloseq

SpiecEasi includes some convenience wrappers to work directly with `phyloseq` objects.

    library(SpiecEasi)
    library(phyloseq)
    ## Load round 2 of American gut project
    data('amgut2.filt.phy')

    se.mb.amgut2 <- spiec.easi(amgut2.filt.phy, method='mb', lambda.min.ratio=1e-2,
                               nlambda=20, pulsar.params=list(rep.num=50))
    ig2.mb <- adj2igraph(getRefit(se.mb.amgut2),  vertex.attr=list(name=taxa_names(amgut2.filt.phy)))

The `plot_network` function provides an easy way to visualize networks with taxonomic information from phyloseq objects. You can specify different taxonomic ranks for coloring nodes and customize the visualization further.

    plot_network(ig2.mb, amgut2.filt.phy, type='taxa', color="Rank3")
    # Warning: `aes_string()` was deprecated in ggplot2 3.0.0.
    # ℹ Please use tidy evaluation idioms with `aes()`.
    # ℹ See also `vignette("ggplot2-in-packages")` for more information.
    # ℹ The deprecated feature was likely used in the phyloseq package.
    #   Please report the issue at <https://github.com/joey711/phyloseq/issues>.
    # This warning is displayed once per session.
    # Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
    # generated.
    # Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
    # ℹ Please use `linewidth` instead.
    # ℹ The deprecated feature was likely used in the phyloseq package.
    #   Please report the issue at <https://github.com/joey711/phyloseq/issues>.
    # This warning is displayed once per session.
    # Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
    # generated.

unnamed-chunk-3-1.png

Session info:

    sessionInfo()
    # R version 4.6.0 (2026-04-24)
    # Platform: x86_64-pc-linux-gnu
    # Running under: Ubuntu 24.04.4 LTS
    #
    # Matrix products: default
    # BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
    # LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.26.so;  LAPACK version 3.12.0
    #
    # locale:
    #  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
    #  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
    #  [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: Etc/UTC
    # tzcode source: system (glibc)
    #
    # attached base packages:
    # [1] stats     graphics  grDevices utils     datasets  methods   base
    #
    # other attached packages:
    # [1] phyloseq_1.57.0  SpiecEasi_2.1.1  BiocStyle_2.41.0
    #
    # loaded via a namespace (and not attached):
    #  [1] gtable_0.3.6        shape_1.4.6.1       xfun_0.57
    #  [4] bslib_0.11.0        ggplot2_4.0.3       Biobase_2.73.1
    #  [7] lattice_0.22-9      vctrs_0.7.3         tools_4.6.0
    # [10] generics_0.1.4      biomformat_1.41.0   stats4_4.6.0
    # [13] parallel_4.6.0      cluster_2.1.8.2     pkgconfig_2.0.3
    # [16] Matrix_1.7-5        huge_1.6            data.table_1.18.4
    # [19] RColorBrewer_1.1-3  S7_0.2.2            S4Vectors_0.51.2
    # [22] lifecycle_1.0.5     compiler_4.6.0      farver_2.1.2
    # [25] stringr_1.6.0       Biostrings_2.81.1   Seqinfo_1.3.0
    # [28] codetools_0.2-20    permute_0.9-10      htmltools_0.5.9
    # [31] sys_3.4.3           buildtools_1.0.0    sass_0.4.10
    # [34] yaml_2.3.12         glmnet_5.0          crayon_1.5.3
    # [37] jquerylib_0.1.4     MASS_7.3-65         cachem_1.1.0
    # [40] vegan_2.7-3         iterators_1.0.14    foreach_1.5.2
    # [43] nlme_3.1-169        digest_0.6.39       stringi_1.8.7
    # [46] reshape2_1.4.5      labeling_0.4.3      maketools_1.3.2
    # [49] splines_4.6.0       ade4_1.7-24         fastmap_1.2.0
    # [52] grid_4.6.0          cli_3.6.6           magrittr_2.0.5
    # [55] survival_3.8-6      ape_5.8-1           withr_3.0.2
    # [58] scales_1.4.0        rmarkdown_2.31      XVector_0.53.0
    # [61] multtest_2.69.0     igraph_2.3.1        pulsar_0.3.13
    # [64] VGAM_1.1-14         evaluate_1.0.5      knitr_1.51
    # [67] IRanges_2.47.1      mgcv_1.9-4          rlang_1.2.0
    # [70] Rcpp_1.1.1-1.1      glue_1.8.1          BiocManager_1.30.27
    # [73] BiocGenerics_0.59.2 jsonlite_2.0.0      R6_2.6.1
    # [76] plyr_1.8.9