R code
Loading packages & data
library(phyloseq)
source("https://raw.githubusercontent.com/mahendra-mariadassou/phyloseq-extended/master/load-extra-functions.R")
#if you want to generate interactiv plot, load plotly and use ggplotly() instead of plot()
#library(plotly)
#if in new session
#data <- path to Rdata file containing phyloseq object
#load(data)
#distance <- path to tsv file containing beta diversity distance matrix to use
# A <- read.table(file=distance, row.names=1)
# dist <- as.dist(A)
Ordianation plots
ord <- ordinate(data, method ="MDS", distance = dist)
p1 <- plot_ordination(data, ord, color = "EnvType") + theme_bw() + ggtitle("MDS")+ theme(plot.title = element_text(hjust = 0.5))
plot(p1)
p2 <- plot_samples(data, ord, color = "EnvType") + theme_bw()+ ggtitle("MDS")+ theme(plot.title = element_text(hjust = 0.5))
plot(p2)
p22 <- p2 + stat_ellipse(aes(group = EnvType))
plot(p22)
Heatmap plot
# change heatmap color scale with color name or hexadecimal code. see http://tools.medialab.sciences-po.fr/iwanthue/
lowCol <- "#ffff00" # yellow
midCol <- "#ffa500" # orange
highCol <- "#ff0000" # red
naCol <- "white" # white!
p3 <- plot_heatmap(data) + scale_fill_gradient2(low = lowCol, mid = midCol, high = highCol, na.value = naCol, trans = log_trans(4), midpoint = log(100, base = 4))+ facet_grid(~EnvType, scales = "free_x") + theme(plot.title = element_text(hjust = 0.5)) + ggtitle("Heatmap plot")
plot(p3)
######### Loading packages & data & parameter setting
library(phyloseq)
source("https://raw.githubusercontent.com/mahendra-mariadassou/phyloseq-extended/master/load-extra-functions.R " )
#if you want to generate interactiv plot, load plotly and use ggplotly() instead of plot()
#library(plotly)
#if in new session, uncomment and complete
#data <- # path to Rdata file
#load(data)
#distance <- # path to Beta diversity tsv file
#A <- read.table(file=distance, row.names=1)
#dist <- as.dist(A)
# to be complete
varExp <- #Experiment variable
method <- "MDS" # ordination method, ex "MDS" (default), "NMDS", "DCA", "CCA", "RDA", "CAP", "DPCoA" or "PCoA"
######### Ordiantion plots #########
ord <- ordinate(data, method =method, distance = dist)
p1 <- plot_ordination(data, ord, color = varExp) + theme_bw() + ggtitle(method)+ theme(plot.title = element_text(hjust = 0.5))
plot(p1)
p2 <- plot_samples(data, ord, color = varExp) + theme_bw()+ ggtitle(method)+ theme(plot.title = element_text(hjust = 0.5))
plot(p2)
g <- paste('p22 <- p2 + stat_ellipse(aes(group =', varExp,'))')
eval(parse(text = g))
plot(p22)
######### Heatmap Plot #########
# change heatmap color scale with color name or hexadecimal code. see http://tools.medialab.sciences-po.fr/iwanthue/
lowCol <- "#ffff00" # yellow
midCol <- "#ffa500" # orange
highCol <- "#ff0000" # red
naCol <- "white" # white!
p3 <- plot_heatmap(data) + scale_fill_gradient2(low = lowCol, mid = midCol, high = highCol,
na.value = naCol, trans = log_trans(4),
midpoint = log(100, base = 4))
e <- paste('~', varExp)
p3 <- p3 + facet_grid(e, scales = "free_x")+ theme(plot.title = element_text(hjust = 0.5))
plot(p3)
Download R code file