install.packages("gridExtra")
install.packages("BiocManager")
BiocManager::install("dada2")
BiocManager::install("ShortRead")
BiocManager::install("DECIPHER")
BiocManager::install("phangorn")
BiocManager::install("ggplot2")
BiocManager::install("phyloseq")
install.packages("tidyverse")
install.packages("dplyr")
install.packages("lemon")

library(dplyr)
library(lemon)
library(tidyverse)
library(reshape2)
library(gridExtra)
library(dada2)
library(ShortRead)
library(DECIPHER)
library(phangorn)
library(ggplot2)
library(phyloseq)
library(tidyverse)
library(RColorBrewer)


#######
# List the names of all files in the trimmomatic directory
path <- "D:/Users/Jesse/Desktop/Provo/Dissertation/CHARS/Analysis"
setwd(path)
pathcut <- "D:/Users/Jesse/Desktop/Provo/Dissertation/CHARS/Analysis/18S_Cut"
output <- "D:/Users/Jesse/Desktop/Provo/Dissertation/CHARS/Analysis/Output"


# List the names of all files in the trimmomatic directory
names <- list.files(pathcut)
names

# Separate into forward and reverse files
namesF <- file.path(pathcut, names[seq(1,12,2)])
namesR <- file.path(pathcut, names[seq(2,12,2)])
namesR

plotQualityProfile(namesF)
plotQualityProfile(namesR)
## Cut around 140

# Make a list of all the sample names simplified from the actual filenames
sample.names18 <- sapply(strsplit(names, ".fastq"), '[', 1)
sample.names18

### Create a new file path to store filtered and trimmed reads
trim_path <- file.path(path, "Filtered")

# Make filtered files
filtF <- file.path(trim_path, paste0(sample.names18[seq(1,12,2)], "_filt.fastq.gz"))
filtR <- file.path(trim_path, paste0(sample.names18[seq(2,12,2)], "_filt.fastq.gz"))


###Let's go
### My Data
## Primers: 18S V9 1391f-1510r
## Amplicon size: ~260 +/- 50 bp



plotQualityProfile(namesF) ## Trim at 140?
plotQualityProfile(namesR) ## Trim at 140bp?


### Create a new file path to store filtered and trimmed reads
trim_path <- file.path(path, "Filtered_140")


# Make filtered files
filtF <- file.path(trim_path, paste0(sample.names18[seq(1,12,2)], "_filt.fastq.gz"))
filtR <- file.path(trim_path, paste0(sample.names18[seq(2,12,2)], "_filt.fastq.gz"))
filtF1 <- file.path(trim_path1, paste0(sample.names18[seq(1,12,2)], "_filt.fastq.gz"))
filtR1 <- file.path(trim_path1, paste0(sample.names18[seq(2,12,2)], "_filt.fastq.gz"))
filtF2 <- file.path(trim_path2, paste0(sample.names18[seq(1,12,2)], "_filt.fastq.gz"))
filtR2 <- file.path(trim_path2, paste0(sample.names18[seq(2,12,2)], "_filt.fastq.gz"))

####
# QUALITY FILTERING AND TRIMMING
####
# Dada2 needs 20nt to merge, so 20 overlap (290 length, 2x160 = 320 -> 30 overlap ? )
# MaxN = no ambigious, Dada2 doesn't like ambiguous so we remove those
# MaxEE = max no estimated errors
# truncQ = truncates the read when quality score drops below threshhold (2 is very bad)

# cutadapt first
# Forward primer (trim off of R2, reverse read)-> GTACACACCGCCCGTC , resulting sequence -> GACGGGCGGTGTGTAC (16bp)
# Reverse primer ("R1)-> TGATCCTTCTGCAGGTTCACCTAC , resulting sequence -> GTAGGTGAACCTGCAGAAGGATCA (23bp)

## from 3' or 5'?
bp_140 <- filterAndTrim(namesF, filtF, namesR, filtR, truncLen = 140, maxN = 0, maxEE = 2, 
                        truncQ = 2, rm.phix = T, compress = T, multithread = F)


bp_140



errF <- learnErrors(filtF)
errR <- learnErrors(filtR)

plotErrors(errF, nominalQ = T)
plotErrors(errR, nominalQ = T)

derepF <- derepFastq(filtF, verbose = T)
derepR <- derepFastq(filtR, verbose = T)

dadaFs <- dada(derepF, err = errF)
dadaRs <- dada(derepR, err = errR)

mergers <- mergePairs(dadaFs, derepF, dadaRs, derepR, verbose = T)


## Sequence table (basically OTU table)
seqtab <- makeSequenceTable(mergers)
dim(seqtab)
### 420 sequences total in our 6 samples

table(nchar(getSequences(seqtab)))

# Identify chimeras
seqtab.nochim <- removeBimeraDenovo(seqtab, method = "consensus", multithread = T, verbose = T)
### Identified 59 bimeras out of 420 input sequences.

# What proportion of reads are NOT chimeric?

sum(seqtab.nochim) / sum(seqtab)
## 96.17%


##### Track lost data - stringent settings ## Sup Figure 1

#track reads
getN <- function(x) sum(getUniques(x))
Track <- cbind(bp_140, sapply(dadaFs, getN), sapply(dadaRs, getN), sapply(mergers, getN), rowSums(seqtab.nochim))
# If processing a single sample, remove the sapply calls: e.g. replace sapply(dadaFs, getN) with getN(dadaFs)
colnames(Track) <- c("input", "filtered", "denoisedF", "denoisedR", "merged", "nonchim")
head(Track)


track.long <- melt(Track,
                   variable.name = "type",
                   value.name = "amount")

track.long <- as_tibble(track.long)
track.long %>%
  mutate(Var1 = str_replace_all(Var1, "_F.fastq.gz", "")) %>%
  mutate(Var1 = str_replace_all(Var1, "([0-9])", "Sample \\1")) %>%
  rename(`Sample Names` = Var1) %>%
  rename(Step = Var2) %>%
  rename(Reads = amount) -> track.long




Trackshow <- ggplot(track.long, aes(x = Step, y = Reads)) +
  geom_boxplot(size = 0.5, alpha = 0.25) + 
  geom_point(aes(colour = `Sample Names`)) +
  geom_point(aes(x = Step, y = Reads, group = `Sample Names`, colour = `Sample Names`), size = 2, shape = 18, alpha=0.5) +
  geom_line(data = track.long, aes(x = Step, y = Reads, group = `Sample Names`, colour = `Sample Names`), size = 1, alpha=0.5)
Trackshow + theme_bw(base_size = 14) + labs(title = "Number of reads per sample through data cleanup")

#####
Track <- cbind(out, sapply(dadaFs, getN), sapply(dadaRs, getN), sapply(mergers, getN), rowSums(seqtab.nochim))
# If processing a single sample, remove the sapply calls: e.g. replace sapply(dadaFs, getN) with getN(dadaFs)
colnames(Track) <- c("input", "filtered", "denoisedF", "denoisedR", "merged", "nonchim")
head(Track)

track.long <- melt(Track,
                   variable.name = "type",
                   value.name = "amount")




##### Using Silva database to assign taxonomy

getwd()
#download.file(url="http://www2.decipher.codes/Classification/TrainingSets/SILVA_SSU_r138_2019.RData", destfile="SILVA_SSU_r138_2019.RData")
download.file(url="http://www2.decipher.codes/Classification/TrainingSets/SILVA_SSU_r132_March2018.RData", destfile ="OldSilva.RData")
download.file(url = "http://www2.decipher.codes/Classification/TrainingSets/PR2_v4_13_March2021.RData", destfile = "PR2.RData")
download.file(url="http://www2.decipher.codes/Classification/TrainingSets/RDP_v18_July2020.RData", destfile ="RDP18S.RData")

## creating DNAStringSet object of our ASVs

dna <- DNAStringSet(getSequences(seqtab.nochim))


# Assign taxonomy
load("PR2.RData")
tax_info_pr <- IdTaxa(test=dna, trainingSet = trainingSet, strand = "both")

#old Silva alternative
load("OldSilva.RData")
tax_info_silva <- IdTaxa(test=dna, trainingSet = trainingSet, strand = "both")

# RDP 18S
load("RDP18S.RData")
tax_info_rdp <- IdTaxa(test=dna, trainingSet = trainingSet, strand = "both")

## Above didn't work great for 18S data
# we could use Dada2's inbuilt assignment
#getwd()
#rdptaxa <- assignTaxonomy(seqtab.nochim, "rdp_train_set_18.fa.gz")
## These results were even worse


# giving our seq headers more manageable names (ASV_1, ASV_2...)
asv_seqs <- colnames(seqtab.nochim)
asv_headers <- vector(dim(seqtab.nochim)[2], mode="character")


for (i in 1:dim(seqtab.nochim)[2]) {
  asv_headers[i] <- paste(">ASV", i, sep="_")
}

# making and writing out a fasta of our final ASV seqs:
asv_fasta <- c(rbind(asv_headers, asv_seqs))

setwd(output)
write(asv_fasta, "ASVs.fa") ### 361 total ASVs

#Make a list of the nematode ASVS

loc = ""

for(i in nem_ids){
  loc <- append(loc,which(asv_headers %in% (paste0(">", i))))
}

loc <- loc[2:length(loc)]
loc <- as.numeric(loc)
loc


asv_nem <- c(rbind(asv_headers[loc], asv_seqs[loc]))
write(asv_nem, "ASVs_nem.fa")


asv_tab <- t(seqtab.nochim)
write.table(asv_tab, "counts.tsv", sep = "\t")
row.names(asv_tab) <- sub(">", "", asv_headers)
write.table(asv_tab, "ASVs_counts.tsv", sep="\t", quote=F, col.names=NA)


# taxonomy table PR:

pr_ranks <- c("rootrank", "kingdom", "division", "phylum", "class", "order", "family", "genus")
asv_tax_pr <- t(sapply(tax_info_pr, function(x) {
  m <- match(pr_ranks, x$rank)
  taxa <- x$taxon[m]
  taxa[startsWith(taxa, "unclassified_")] <- NA
  taxa
}))


colnames(asv_tax_pr) <- pr_ranks
rownames(asv_tax_pr) <- getSequences(seqtab.nochim)

# taxonomy table Silva:

silva_ranks <- c("rootrank", "domain", "major_clade", "superkingdom", "kingdom", "subkingdom", "infrakingdom", "phylum", "subphylum", "class", "subclass", "infraclass", "order", "suborder", "superfamily", "family", "genus")
asv_tax_silva <- t(sapply(tax_info_silva, function(x) {
  m <- match(silva_ranks, x$rank)
  taxa <- x$taxon[m]
  taxa[startsWith(taxa, "unclassified_")] <- NA
  taxa
}))


colnames(asv_tax_silva) <- silva_ranks
rownames(asv_tax_silva) <- getSequences(seqtab.nochim)


#rownames(asv_tax) <- gsub(pattern=">", replacement="", x=asv_headers)


write.table(asv_tax_pr, "Output/PR/ASVs_taxonomy_PR.tsv", sep = "\t", quote=F, col.names=NA)
write.table(asv_tax_silva, "Output/Silva/ASVs_taxonomy_Silva.tsv", sep = "\t", quote=F, col.names=NA)

### Merge Silva and PR manually

tax_info_merged <- read_csv("Output/Merged_PR_Silva.csv") %>%
  select(2,3,5,8,10,13)

asv_tax_merged <- as.matrix(tax_info_merged)
rownames(asv_tax_merged) <- getSequences(seqtab.nochim) 

#### Filled in the gaps with Genbank BLAST


tax_info_all <- read_csv("Output/Genbank_Taxonomy.csv") %>%
  select(2,3,5,8,10,13)

asv_tax_all <- as.matrix(tax_info_all)
rownames(asv_tax_all) <- getSequences(seqtab.nochim)

### load sequences from file to skip steps before

path <- "D:/Users/Jesse/Desktop/Provo/Dissertation/CHARS/Analysis"
seqtab.nochim <- as.matrix(read.csv("seqtab.nochim.csv"))


###### Phylogenetic tree

sequences <- getSequences(seqtab.nochim)
names(sequences) <- sequences
alignment <- AlignSeqs(DNAStringSet(sequences), anchor = NA)

phang.align <- phyDat(as(alignment, "matrix"), type = "DNA")
#Create distance matrix
dm <- dist.ml(phang.align)
treeNJ <- NJ(dm)

fit <- pml(treeNJ, data = phang.align)

fitGTR <- update(fit, k = 4, inv = 0.2)
fitGTR <- optim.pml(fitGTR, model = "GTR", optInv = T, optGamma = T, rearrangement = "stochastic", control = pml.control(trace = 0))

fitGTR
## GTR is generalized time-reversible with Gamma rate variation maximum likelihood tree


# Import tree into phyloseq


samples.out <- rownames(seqtab.nochim)
subject <- c("1_Frost_Heap", "2_Carex_Sci", "3_Sedge_Peat", "4_Shrub_Sedge", "5_Frost_Dril", "6_Frost Heap")
subject <- c("NV4", "V1", "V2", "V3", "NV5", "NV6")
Soil <- c("Non-Vegetated", "Vegetated", "Vegetated", "Vegetated", "Non-Vegetated", "Non-Vegetated")
samdf <- data.frame(Subject = subject, Condition = Soil)


rownames(samdf) <- samples.out

ps <- phyloseq(otu_table(seqtab.nochim, taxa_are_rows = F),
               sample_data(samdf),
               tax_table(asv_tax_all),
               phy_tree(fitGTR$tree))


dna <- Biostrings::DNAStringSet(taxa_names(ps))
names(dna) <- taxa_names(ps)
ps <- merge_phyloseq(ps, dna)
taxa_names(ps) <- paste0("ASV", seq(ntaxa(ps)))
head(ps@tax_table, n=1)

## Plot the tree

set.seed(711)


phy_tree(ps) <- root(phy_tree(ps), sample(taxa_names(ps), 1), resolve.root = T)
is.rooted(phy_tree(ps)) #TRUE
phy_tree(ps)

ntaxa(ps) # 361 is a bit too much for a single tree

#prune to top 50 
top50 <- names(sort(taxa_sums(ps), decreasing=TRUE))[1:50]

physeq1 = prune_taxa(top50, ps)
physeq2 = prune_taxa(taxa_names(ps)[51:100], ps)
physeq3 = prune_taxa(taxa_names(ps)[101:150], ps)
physeq4 = prune_taxa(taxa_names(ps)[151:200], ps)
physeq5 = prune_taxa(taxa_names(ps)[201:250], ps)
physeq6 = prune_taxa(taxa_names(ps)[251:300], ps)
physeq7 = prune_taxa(taxa_names(ps)[301:350], ps)

radial <- plot_tree(physeq1, color="Condition", ladderize="left") + coord_polar(theta="y")
radial + theme_bw()

tree1 <- plot_tree(physeq1, ladderize = "left", color = "Condition")
tree1 + 
  scale_colour_brewer(palette = "Set1") + labs(x = "", y = "")
tree2 <- plot_tree(physeq1, ladderize = "left", color = "Condition")
tree2 +
  scale_colour_brewer(palette = "Set1")
treeall <- plot_tree(ps, ladderize = "left", color = "Condition")
treeall + scale_colour_brewer(palette = "Set1") + labs(legend = "Soil Type", title = "Phylogeny of all collected ASVs and their presence in humic and mineral soils")


# different subsets
tree4 <- plot_tree(physeq2, ladderize = "left", color = "Condition")
tree4 +
  scale_colour_brewer(palette = "Set1")
tree5 <- plot_tree(physeq3, ladderize = "left", color = "Condition")
tree5 +
  scale_colour_brewer(palette = "Set1")
tree6 <- plot_tree(physeq4, ladderize = "left", color = "Condition")
tree6 +
  scale_colour_brewer(palette = "Set1")
tree7 <- plot_tree(physeq5, ladderize = "left", color = "Condition")
tree7 +
  scale_colour_brewer(palette = "Set1")
tree8 <- plot_tree(physeq6, ladderize = "left", color = "Condition")
tree8 +
  scale_colour_brewer(palette = "Set1")
tree9 <- plot_tree(physeq7, ladderize = "left", color = "Condition")
tree9 +
  scale_colour_brewer(palette = "Set1")

### Nematode and Arthropod trees for Figure 7
# subset by order 
ps.rel <- transform_sample_counts(ps, function(OTU) OTU/sum(OTU))

ps.arth <- subset_taxa(ps, class %in% c("Insecta", "Arachnida", "Ellipura"))
arth_tree <- plot_tree(ps.arth, ladderize = "right", color = "Condition", label.tips = "taxa_names", base.spacing = 0.04, plot.margin = 0.1, size = "abundance") 
arth_tree + scale_colour_brewer(palette = "Set1")
plot_tree(ps.arth, label.tips = "taxa_names")

ps.nem <- subset_taxa(ps, phylum == "Nematoda")
ps.nem
nem_tree <- plot_tree(ps.nem, ladderize = "left", color = "Condition", label.tips = "class", base.spacing = 0.04, plot.margin = 0.2, size = "abundance", text.size = 3) 
nem_tree + scale_colour_brewer(palette = "Set1")
plot_tree(ps.nem, method = "treeonly", ladderize = "left")


## Look at diversity/richness

# Figure 5
richness1 <- plot_richness(ps, x= "Subject", measures=c("Observed", "Shannon", "Simpson"), color="Condition")
richness1$data$Subject <- factor(richness1$data$Subject, levels = c("V1", "V2", "V3", "NV4", "NV5", "NV6"))
richness1 + theme_bw(base_size = 14) + labs(x = "Sample")+
  scale_colour_brewer(palette = "Set1") +
  labs(title = "Observed Features, Shannon and Simpson diversity metrics")
## Common phyla subset
ps.common <- subset_taxa(ps, phylum %in% c("Arthropoda", "Nematoda", "Annelida", "Platyhelminthes", "Rotifera", "Tardigrada", "Ascomycota"))
ps.common <- transform_sample_counts(ps.common, function(OTU) OTU/sum(OTU))
### Easier to split them up, looking at the common phyla
# By phylum, class and order ## Figure 2
rp1 <- plot_bar(ps.common, x = "Subject", fill = "phylum") + labs(y = "Relative Abundance", x = "Sample", title = "Relative proportion of the most common phyla") + theme_bw(base_size = 14)
rp1$data$Subject <- factor(rp1$data$Subject, levels = c("V1", "V2", "V3", "NV4", "NV5", "NV6"))
rp1 ## Figure 2
ps.nematoda <- subset_taxa(ps, phylum %in% c("Nematoda"))
ps.nematoda <- transform_sample_counts(ps.nematoda, function(OTU) OTU/sum(OTU))
ps.arthropoda <- subset_taxa(ps, phylum %in% c("Arthropoda"))
ps.arthropoda <- transform_sample_counts(ps.arthropoda, function(OTU) OTU/sum(OTU))
rp2 <- plot_bar(ps.nematoda, x = "Subject", fill = "order") + labs(y = "Abundance", x = "Sample", title = "Relative abundance of Nematode orders") + theme_bw(base_size = 14)
rp3 <- plot_bar(ps.arthropoda, x = "Subject", fill = "order") + labs(y = "Abundance", x = "Sample", title = "Relative abundance of Arthropod orders") + theme_bw(base_size = 14)
rp2$data$Subject <- factor(rp2$data$Subject, levels = c("V1", "V2", "V3", "NV4", "NV5", "NV6"))
rp3$data$Subject <- factor(rp3$data$Subject, levels = c("V1", "V2", "V3", "NV4", "NV5", "NV6"))
rp2 ## Figure 3
rp3 ## Figure 4

## Figure 6
ps.prop <- transform_sample_counts(ps, function(otu) otu/sum(otu))
ord.nmds.bray <- ordinate(ps.prop, method="NMDS", distance="bray")
ord.nmds.unif <- ordinate(ps.prop, method="NMDS", distance="unifrac")
ord.nmds.wunif <- ordinate(ps.prop, method="NMDS", distance="wunifrac")
ord.nmds.jsd <- ordinate(ps.prop, method="NMDS", distance="jsd")
p1 <- plot_ordination(ps.prop, ord.nmds.bray, color="Condition", title="(A) Bray NMDS", label = "Subject") + theme_bw(base_size = 14) + theme(legend.position = "none")
p2 <- plot_ordination(ps.prop, ord.nmds.unif, color="Condition", title="(B) UniFrac NMDS", label = "Subject") + theme_bw(base_size = 14) + theme(legend.position = "none")
p3 <- plot_ordination(ps.prop, ord.nmds.wunif, color="Condition", title="(C) W Unifrac NMDS", label = "Subject") + theme_bw(base_size = 14) + theme(legend.position = "none")
p4 <- plot_ordination(ps.prop, ord.nmds.jsd, color="Condition", title="(D) Jensen-Shannon NMDS", label = "Subject") + theme_bw(base_size = 14)
grid_arrange_shared_legend(p1,p2,p3,p4, ncol = 2, nrow = 2) 

## Sup Fig 3
ps.prop_n <- transform_sample_counts(ps.nematoda, function(otu) otu/sum(otu))
ord.nmds.bray.n <- ordinate(ps.prop_n, method="NMDS", distance="bray")
ord.nmds.unif.n <- ordinate(ps.prop_n, method="NMDS", distance="unifrac")
ord.nmds.wunif.n <- ordinate(ps.prop_n, method="NMDS", distance="wunifrac")
ord.nmds.jsd.n <- ordinate(ps.prop_n, method="NMDS", distance="jsd")
ord.nmds.bray.n <- ordinate(ps.prop_n, method="NMDS", distance="bray")
p5 <- plot_ordination(ps.prop_n, ord.nmds.bray.n, color="Condition", title="(A) Bray NMDS", label = "Subject") + theme_bw(base_size = 14) + theme(legend.position = "none")
p6 <- plot_ordination(ps.prop_n, ord.nmds.unif.n, color="Condition", title="(B) UniFrac NMDS", label = "Subject") + theme_bw(base_size = 14) + theme(legend.position = "none")
p7 <- plot_ordination(ps.prop_n, ord.nmds.wunif.n, color="Condition", title="(C) W Unifrac NMDS", label = "Subject") + theme_bw(base_size = 14) + theme(legend.position = "none")
p8 <- plot_ordination(ps.prop_n, ord.nmds.jsd.n, color="Condition", title="(D) Jensen-Shannon NMDS", label = "Subject") + theme_bw(base_size = 14)
grid_arrange_shared_legend(p5,p6,p7,p8, ncol = 2, nrow = 2)

## Sup Fig 4
ps.prop_a <- transform_sample_counts(ps.arthropoda, function(otu) otu/sum(otu))
ord.nmds.bray.a <- ordinate(ps.prop_a, method="NMDS", distance="bray")
ord.nmds.unif.a <- ordinate(ps.prop_a, method="NMDS", distance="unifrac")
ord.nmds.wunif.a <- ordinate(ps.prop_a, method="NMDS", distance="wunifrac")
ord.nmds.jsd.a <- ordinate(ps.prop_a, method="NMDS", distance="jsd")
p9 <- plot_ordination(ps.prop_a, ord.nmds.bray.a, color="Condition", title="(A) Bray NMDS", label = "Subject") + theme_bw(base_size = 14) + theme(legend.position = "none")
p10 <- plot_ordination(ps.prop_a, ord.nmds.unif.a, color="Condition", title="(B) UniFrac NMDS", label = "Subject") + theme_bw(base_size = 14) + theme(legend.position = "none")
p11 <- plot_ordination(ps.prop_a, ord.nmds.wunif.a, color="Condition", title="(C) W Unifrac NMDS", label = "Subject") + theme_bw(base_size = 14) + theme(legend.position = "none")
p12 <- plot_ordination(ps.prop_a, ord.nmds.jsd.a, color="Condition", title="(D) Jensen-Shannon NMDS", label = "Subject") + theme_bw(base_size = 14)
grid_arrange_shared_legend(p9,p10,p11,p12, ncol = 2, nrow = 2)

# Facet plot ## Sup Fig 2
ps.common1 <- subset_taxa(ps.rel, phylum %in% c("Arthropoda", "Platyhelminthes", "Tardigrada", "Annelida"))
ps.common2 <- subset_taxa(ps.rel, phylum %in% c("Ascomycota", "Nematoda", "Rotifera", "Basidiomycota"))

facet_class1 <- plot_bar(ps.common1, x = "Subject", fill = "class", facet_grid=~phylum)
facet_class1$data$Subject <- factor(facet_class1$data$Subject, levels = c("NV6", "NV5", "NV4", "V3", "V2", "V1"))
facet_class2 <- plot_bar(ps.common2, x = "Subject", fill = "class", facet_grid=~phylum)
facet_class2$data$Subject <- factor(facet_class2$data$Subject, levels = c("NV6", "NV5", "NV4", "V3", "V2", "V1"))
facet_class1 <- facet_class1 + theme_bw() + scale_colour_brewer(palette = "Set2") + coord_flip() + facet_wrap(~phylum, ncol = 1) + theme(axis.title.y = element_blank(), axis.title.x = element_blank())
facet_class2 <- facet_class2 + theme_bw() + scale_colour_brewer(palette = "Set2") + coord_flip() + facet_wrap(~phylum, ncol = 1) + theme(axis.title.y = element_blank()) + labs(x = "Relative Abundance")
grid.arrange(facet_class1, facet_class2, ncol = 1, left = "Sample")