knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

biomeViz

biomeViz is part of the RIVM-ToolBox project aimed at providing standard set of tools that interact with open tools for a wide array of data analytics, including microbiomics. The RIVM-ToolBox is a set of individual R tools focused towards different goals/functionalities.

library(biomeViz)

Categorical and numeric plot

Visualize one categorical column and one numeric column in sample_data.

library(biomeUtils)
library(biomeViz)
library(dplyr)
library(microbiome)
library(ggplot2)
library(gghalves)
library(patchwork)

ps <- FuentesIliGutData
# calculate Shannon diversity using microbiome::diversity and add it to
# the sample_data in phyloseq using biomeUtils::mutateSampleData()
ps <- mutateSampleData(ps,
                       Shannon = microbiome::diversity(ps, "shannon")[,1])
plotByGroup(ps,
            x.factor="ILI",
            y.numeric = "Shannon") +
  gghalves::geom_half_point(
    ggplot2::aes_string(fill="ILI"),
    side = "l",
    range_scale = .4,
    alpha = 0.25,
    shape = 21) +
  scale_fill_manual(values = c("#3d6721", "#a86826", "#006c89"), guide = "none")

Scatter plot

library(biomeUtils)
library(biomeViz)
library(dplyr)
library(microbiome)
library(ggplot2)
plotScatterViz(ps, x_numeric = "Shannon", y_numeric = "BMI",
               color_var = "ILI") +
  scale_fill_manual(values=c("steelblue", "brown3", "grey70"))+
  scale_fill_manual(values=c("steelblue", "brown3", "grey70"))

Theme showcase

p.base <- plotByGroup(ps,
                      x.factor="ILI",
                      y.numeric = "Shannon") +
  gghalves::geom_half_point(
    ggplot2::aes_string(fill="ILI"),
    side = "l",
    range_scale = .4,
    alpha = 0.25,
    shape = 21) + 
  labs(subtitle = "base plot") +
  theme_bw() +
  scale_fill_biomeViz(palette = "viz3") 


p.bw <- plotByGroup(ps,
                    x.factor="ILI",
                    y.numeric = "Shannon") +
  gghalves::geom_half_point(
    ggplot2::aes_string(fill="ILI"),
    side = "l",
    range_scale = .4,
    alpha = 0.25,
    shape = 21) +
  scale_fill_biomeViz(palette = "viz3") +
  labs(subtitle = "biomeViz bw") +
  theme_biomViz_bw() 

p.min <- plotByGroup(ps,
                    x.factor="ILI",
                    y.numeric = "Shannon") +
  gghalves::geom_half_point(
    ggplot2::aes_string(fill="ILI"),
    side = "l",
    range_scale = .4,
    alpha = 0.25,
    shape = 21) +
  scale_fill_biomeViz(palette = "viz3") +
  labs(subtitle = "biomeViz minimal") +
  theme_biomViz_minimal() 

p.gen <- plotByGroup(ps,
                    x.factor="ILI",
                    y.numeric = "Shannon") +
  gghalves::geom_half_point(
    ggplot2::aes_string(fill="ILI"),
    side = "l",
    range_scale = .4,
    alpha = 0.25,
    shape = 21) +
  scale_fill_biomeViz(palette = "viz3") + 
  labs(subtitle = "biomeViz general") +
  theme_biomViz() 

((p.base | p.bw )  / ( p.min  | p.gen ) ) + plot_layout(guides = "collect")

Top features

Plot the features with the highest abundance in all samples.

library(biomeUtils)
library(biomeViz)
plotTopAbundant(SprockettTHData,
                taxa_level = "Family",
                top=10L,
                aes(color=Phylum)) +
  theme_biomViz_minimal() +
  scale_colour_biomeViz_summer()

Heatmap

library(biomeUtils)
library(biomeViz)
library(microbiome)
library(dplyr)
library(tidyHeatmap)

#  Transform to relative abundance
ps <- FuentesIliGutData %>%
  microbiome::transform("compositional")

# Select taxa to plot. This avoid overcrowding 
select_taxa <- findTopTaxa(ps, top= 10, method="mean")

p <- plotTidyHeatmap(ps, select_taxa = select_taxa,
                     group_samples_by = "ILI",
                     add_taxa_label = FALSE,
                     cluster_rows = FALSE,
                     .scale = "none", # no scaling only relative abundance
                     transform = NULL,
                     palette_grouping = list(biomeViz_palettes$viz3)) %>%
  add_line(age)
p

Raincloud

Rain clouds are effective to visualize data. Read more about their utility here Allen M, Poggiali D, Whitaker K et al. Raincloud plots: a multi-platform tool for robust data visualization [version 2; peer review: 2 approved]. Wellcome Open Res 2021, 4:63 link

library(biomeUtils)
library(biomeViz)
library(microbiome)
library(ggplot2)
library(dplyr)

ps <- FuentesIliGutData %>%
  microbiome::aggregate_taxa("Genus") %>%
  microbiome::transform("compositional") 

plotTaxaRaincloud(ps,
                  taxa ="Bacteroides",
                  group_samples_by = "ILI",
                  opacity = 0.25,
                  shape_point = 21) + # combine with ggplot2 for improvements
  labs(y = "Relative abundance",
       x = "",
       subtitle = expression(paste("Raincloud plot showing the distribution of ",italic("Bacteroides")))) +
  theme_biomViz()+
  scale_fill_manual(values = c("#3d6721", "#a86826", "#006c89"), guide = "none") +
  scale_color_manual(values = c("#3d6721", "#a86826", "#006c89"), guide = "none") +
  theme(plot.subtitle = element_text(margin = margin(t = 5, b = 10)),
        plot.margin = margin(10, 25, 10, 25)) 

Plot CLR abundance of multiple taxa.

ps <- FuentesIliGutData %>%
  microbiome::aggregate_taxa("Genus") %>%
  microbiome::transform("clr") 

taxa.to.plot <- c("Bacteroides","Blautia","Roseburia","Faecalibacterium")

plotTaxaRaincloud(ps,
                  taxa = taxa.to.plot,
                  group_samples_by = "ILI",
                  opacity = 0.25,
                  shape_point = 21) + # combine with ggplot2 for improvements
  labs(y = "CLR Abundance",
       x = "") + 
  theme_biomViz_bw() + 
  theme(strip.text.x = element_text(face = "italic")) +
  scale_fill_manual(values = c("#3d6721", "#a86826", "#006c89"), guide = "none") +
  scale_color_manual(values = c("#3d6721", "#a86826", "#006c89"), guide = "none")  

PCoA plot

A Principal Coordinates Analysis for phyloseq object. To visualize similarities/dissimilarities between samples in 2D ordination. This function extends the phyloseq ordination plots to include taxa that correlate with chosen axis and plots them along with a side boxplot for comparing inter-sample variation within groups.

library(biomeUtils)
library(dplyr)
library(ggside)
ps <- FuentesIliGutData %>%
  microbiome::transform("compositional") %>%
  mutateTaxaTable(FeatureID = taxa_names(FuentesIliGutData))
plotPCoA(x =ps,
         group_var = "ILI",
         ord_method = "PCoA",
         dist_method = "bray",
         seed = 1253,
         cor_method = "spearman",
         verbose = TRUE,
         padj_cutoff = 0.05,
         padj_method = "fdr",
         arrows = TRUE,
         label_col = "grey30",
         plot_centroids = TRUE,
         add_side_box = TRUE,
         axis_plot = c(1:2),
         point_shape = 21,  # point_shape
         point_alpha = 0.5) +
  theme_biomViz_minimal() + 
  scale_color_manual(values = c("#3d6721", "#a86826", "#006c89")) +
  scale_fill_manual(values = c("#3d6721", "#a86826", "#006c89"))
sessionInfo()


RIVM-IIV-Microbiome/biomeViz documentation built on July 20, 2022, 3:52 a.m.