Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. # helper functions
  2. plot_sig <- function(sigtab, x="Species", color="Species", rank1="Family", rank2="Species", alpha=0.05, title=""){
  3. sig = sigtab[which(sigtab$padj < alpha), ]
  4. y = tapply(sig$log2FoldChange, sig[, rank1], function(z) max(z))
  5. y = sort(y, TRUE)
  6. sig[, rank1] = factor(as.character(sig[, rank1]), levels=names(y))
  7. y = tapply(sig$log2FoldChange, sig[, rank2], function(z) max(z))
  8. y = sort(y, TRUE)
  9. sig[, rank2] = factor(as.character(sig[, rank2]), levels=names(y))
  10. return(ggplot(sig, aes_string(x=x, y="log2FoldChange", color=color)) +
  11. geom_point(aes(size=baseMean)) + guides(col = guide_legend(ncol = 1)) +
  12. theme(axis.text.x = element_text(angle = 90, vjust=0.5)) + ggtitle(title))
  13. }
  14. plot_volcano <- function(sigtab, color="Family", label="Species", title=""){
  15. our_copy <- sigtab
  16. our_copy[,"neg.log10.padj"] <- -log10(our_copy$padj)
  17. return(ggplot(our_copy, aes_string(x="log2FoldChange", y="neg.log10.padj", color=color, label=label)) +
  18. geom_point(size=3) + geom_label() +
  19. theme(axis.text.x = element_text(angle = -90, hjust = 0, vjust=0.5), legend.position="bottom") +
  20. ggtitle(title) + geom_hline(aes(yintercept=-log10(.05))) + geom_vline(aes(xintercept=1)) + geom_vline(aes(xintercept=-1)))
  21.  
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement