-
Notifications
You must be signed in to change notification settings - Fork 7
03. Diversities
Sudarshan edited this page Oct 2, 2017
·
2 revisions
This is an example of calculating alpha diversities using microbiome
R package and how to do simple statistical tests. For more information on diversities please check the microbiome tutorial
library(microbiome)
library(microbiomeutilities)
library(ggpubr)
data("DynamicsIBD")
set.seed(9037)
pseq.rare <- rarefy_even_depth(DynamicsIBD, sample.size = 14000)
print(pseq.rare)
# Check the taxonomic ranks and edit them.
colnames(tax_table(pseq.rare)) <-c("Domain", "Phylum", "Order", "Class", "Family", "Genus", "Species")
For this example, a subset of conditions will be used.
ps1 <- subset_samples(pseq.rare, ibd_subtype == "HC")
ps2 <- subset_samples(pseq.rare, ibd_subtype == "CCD")
ps3 <- subset_samples(pseq.rare, ibd_subtype == "ICD_r")
ps4 <- subset_samples(pseq.rare, ibd_subtype == "UC")
ps5 <- merge_phyloseq(ps1, ps2,ps3,ps4)
ps5 <- prune_taxa(taxa_sums(ps5) > 0, ps5)
Now calculate the diversities.
ibd.div <- diversities(ps5, index = "all")
ibd.meta <- meta(ps5)
ibd.meta$sam_name <- rownames(ibd.meta)
ibd.div$sam_name <- rownames(ibd.div)
div.df <- merge(ibd.div,ibd.meta, by = "sam_name")
colnames(div.df)
p <- ggboxplot(div.df, x = "ibd_subtype", y = "shannon",
fill = "ibd_subtype", palette = "jco")
Now comparing these conditions.
# list the groups we need to compare. Here, variables under ibd subtype will be tested.
lev <- levels(div.df$ibd_subtype) # get the variables
# make a pairwise list that we want to compare.
L.pairs <- combn(seq_along(lev), 2, simplify = FALSE, FUN = function(i)lev[i])
Now calculate and plot
p <- p + stat_compare_means(comparisons = L.pairs)
+ stat_compare_means(label.y = max(ibd.div$shannon + 3))
print(p)
For more details please check ggpubr: Publication Ready Plots.
Leo Lahti, Sudarshan Shetty et al. (2017). Tools for microbiome analysis in R. Version 0.99.87. URL: http://microbiome.github.com/microbiome
A. Kassambara. ggpubr R Package: ggplot2-Based Publication Ready Plots