Chapter 12 Supp figure 6

Bar chart showing the divergence of samples within each participant for the SCFA relative abundance profiles. This is based on the Bray-Curtis dissimilarity metric.

12.1 Intra group variability

#Packages
library(microbiome)
library(dplyr)
library(tidyverse)
library(patchwork)
#Load even sampling depth physeq produced for figure 4
load(file = "./data/lipid_physeq_1k_object")
physeq_no_etoh <- subset_samples(physeq_1k, Buffer.type != "Ethanol")


#Intra participant
betas <- list()
groups <- as.character(unique(meta(physeq_no_etoh)$Sample.number))
for (g in groups) {
  #Pick samples for this group
  g_physeq <- subset_samples(physeq_no_etoh, Sample.number == g)
  #Get median abundances of the samples
  reference <- apply(abundances(g_physeq), 1, median)
  #Divergence of samples
  b <- divergence(g_physeq, reference, method = "bray")
  betas[[g]] <- b
}
# boxplot
df <- as.data.frame(unlist(betas))
s<- rownames(df)
si<- as.data.frame(s)
si<- separate(si, s, into = c('Patient','sample'), sep = ".Sample")
df1<- bind_cols(df, si)

p<- ggplot(df1, aes(x = Patient, y = `unlist(betas)`))+ geom_boxplot() + ylab('') + xlab('Participant number') + ylab("Bray-Curtis distance")

#Intra buffer
betas <- list()
groups <- as.character(unique(meta(physeq_1k)$Buffer.type))
for (g in groups) {
  #Pick samples for this group
  g_physeq <- subset_samples(physeq_1k, Buffer.type == g)
  #Get median abundances of the samples
  reference <- apply(abundances(g_physeq), 1, median)
  #Divergence of samples
  b <- divergence(g_physeq, reference, method = "bray")
  betas[[g]] <- b
}
# boxplot
df <- as.data.frame(unlist(betas))
s<- rownames(df)
si<- as.data.frame(s)
si<- separate(si, s, into = c('Patient','sample'), sep = ".Sample")
df1<- bind_cols(df, si)

b<- ggplot(df1, aes(x = Patient, y = `unlist(betas)`))+ geom_boxplot() + ylab('') + xlab('Bufferused') + ylab("Bray-Curtis distance")


ggsave(plot = p,
       "./figures/lipid_intra_patient_variance.png",
       device = "png", units = "mm", height = 150, width = 200)