Skip to content

Instantly share code, notes, and snippets.

View bvaisvil's full-sized avatar
🦖

Benjamin Vaisvil bvaisvil

🦖
View GitHub Profile
@bvaisvil
bvaisvil / helper.R
Created August 8, 2019 17:03
Metagenomics helper functions for plotting significantly differentially expressed ASVs/OTUs
# helper functions
plot_sig <- function(sigtab, x="Species", color="Species", rank1="Family", rank2="Species", alpha=0.05, title=""){
sig = sigtab[which(sigtab$padj < alpha), ]
y = tapply(sig$log2FoldChange, sig[, rank1], function(z) max(z))
y = sort(y, TRUE)
sig[, rank1] = factor(as.character(sig[, rank1]), levels=names(y))
y = tapply(sig$log2FoldChange, sig[, rank2], function(z) max(z))
y = sort(y, TRUE)
sig[, rank2] = factor(as.character(sig[, rank2]), levels=names(y))
return(ggplot(sig, aes_string(x=x, y="log2FoldChange", color=color)) +