R code
Loading packages & data
library(phyloseq)
library(ggplot2)
library(gridExtra)
library(reshape2)
source("https://raw.githubusercontent.com/mahendra-mariadassou/phyloseq-extended/master/load-extra-functions.R")
#if in new session
#data <- path to Rdata file
#load(data)
varExp <- #Experiment variable to split plot
method <- #Beta diversity method name #To show all available distances: distanceMethodList
fileBeta <- "beta_diversity.tsv" # output file path
Dist as heatmap plot
## Order samples according to grouping variable
sampleOrder <- levels(reorder(sample_names(data), as.numeric(get_variable(data, varExp))))
dist.a <- distance(data, method = method)
pa <- plot_dist_as_heatmap(dist.a, order = sampleOrder, title = method) +
theme(plot.title = element_text(hjust = 0.5))
plot(pa)
Save distance matrix
a <- as.matrix(dist.a)
write.table(a, fileBeta, sep="\t", quote=FALSE, col.names=NA)
library(phyloseq)
library(ggplot2)
library(gridExtra)
library(reshape2)
source("https://raw.githubusercontent.com/mahendra-mariadassou/phyloseq-extended/master/load-extra-functions.R
")
#if in new session
#data <- path to Rdata file
#load(data)
varExp <- #Experiment variable to split plot
method <- #Beta diversity method name
fileBeta <- #path to output Beta diversity file
#To show all available distances: distanceMethodList
## Order samples according to grouping variable
sampleOrder <- levels(reorder(sample_names(data), as.numeric(get_variable(data, varExp))))
dist.a <- distance(data, method = method)
pa <- plot_dist_as_heatmap(dist.a, order = sampleOrder, title = method) +
theme(plot.title = element_text(hjust = 0.5))
plot(pa)
a <- as.matrix(dist.a)
write.table(a, fileBeta , sep="\t", quote=FALSE, col.names=NA)