joey711 / phyloseq

phyloseq is a set of classes, wrappers, and tools (in R) to make it easier to import, store, and analyze phylogenetic sequencing data; and to reproducibly share that data and analysis with others. See the phyloseq front page:
http://joey711.github.io/phyloseq/
586 stars 186 forks source link

What package is needed for the "plot_composition" function? #654

Closed amco130 closed 8 years ago

amco130 commented 8 years ago

I've been going through the following tutorial:

http://genoweb.toulouse.inra.fr/~formation/15_FROGS/April2016/R_phyloseq/phyloseq_formation_toulouse_201604.pdf

I can't perform the following (Slide 47):

p <- plot_composition(food, "Kingdom", "Bacteria", "Phylum", numberOfTaxa = 5, fill = "Phylum")

Error: could not find function "plot_composition"

I am guessing that I am missing a package but can't seem to figure out which one I need.

Any help?

amco

jeffkimbrel commented 8 years ago

It looks like it is a custom function that can be found in the same folder as that pdf:

http://genoweb.toulouse.inra.fr/%7Eformation/15_FROGS/April2016/R_phyloseq/Codes_R/phyloseq/R_scripts/graphical_methods.R

From that file:

## Plot composition at taxaRank2 level within taxa taxaSet1 at taxaRank1 level
## Restricts plot to numberOfTaxa taxa
plot_composition <- function(physeq, taxaRank1 = "Phylum", taxaSet1 = "Proteobacteria",
                             taxaRank2 = "Family", numberOfTaxa = 9, fill = NULL,
                             x = "Sample", y = "Abundance", facet_grid = NULL) {
  ## Args:
  ## - physeq: phyloseq class object
  ## - taxaRank1: taxonomic level in which to do the first subsetting
  ## - taxaSet1: subset of level taxaRank1 to use
  ## - taxaRank2: taxonomic level used to agglomerate
  ## - numberOfTaxa: number of (top) taxa to keep at level taxaRank2
  ##
  ## Returns:
  ## - ggplot2 graphics
  ggdata <- ggformat(physeq, taxaRank1, taxaSet1, taxaRank2, numberOfTaxa)
  p <- ggplot(ggdata, aes_string(x = x, y = y, fill = fill, color = fill, group = "Sample"))
  ## Manually change color scale to assign grey to "Unknown" (if any)
  if (!is.null(fill) && any(c("Unknown", "Other") %in% unique(ggdata[, fill]))) {
      ranks <- as.character(unique(ggdata[, fill]))
      ranks <- ranks[ ! ranks %in% c("Unknown", "Other")]
      colvals <- c(gg_color_hue(length(ranks)), "grey45", "black")
      names(colvals) <- c(ranks, "Unknown", "Other")
      ## Now add the manually re-scaled layer with Unassigned as grey
      p <- p + scale_fill_manual(values=colvals) + scale_color_manual(values = colvals)

  }
  p <- p + geom_bar(stat = "identity", position = "stack")
  if ( !is.null(facet_grid)) {
    p <- p + facet_grid(facets = facet_grid, scales = "free_x")
  }
  p <- p + theme(axis.text.x=element_text(angle=90), axis.title.x=element_blank())
  p <- p + ggtitle(paste("Composition within", taxaSet1, "(", numberOfTaxa, "top", taxaRank2, ")"))
  return(p)
}
slvrshot commented 8 years ago

@jeffkimbrel

How do you add the function to phyloseq?

spholmes commented 8 years ago

One doesn't add the function to phyloseq, one sources the file where the function is defined, then it is known in your current R session.

On Fri, Aug 19, 2016 at 11:42 PM, slvrshot notifications@github.com wrote:

@jeffkimbrel https://github.com/jeffkimbrel

How do you add the function to phyloseq?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/joey711/phyloseq/issues/654#issuecomment-241183266, or mute the thread https://github.com/notifications/unsubscribe-auth/ABJcvew28jCCTTbIVDvqXMOkftSjUEsvks5qhqG8gaJpZM4JkEd6 .

Susan Holmes Professor, Statistics and BioX John Henry Samter Fellow in Undergraduate Education Sequoia Hall, 390 Serra Mall Stanford, CA 94305 http://www-stat.stanford.edu/~susan/

slvrshot commented 8 years ago

Well how would I source it? Sorry if I sound ignorant. I've never done it before.

spholmes commented 8 years ago

On Page 9 of the slide show they have the command: source("Custom_Functions.R")

You need that file: make sure you understand whether you really need it, my view is that you are MUCH better off following the original tutorials which have all the information and don't try to rarefy. (see here for why: http://joey711.github.io/phyloseq-extensions/DESeq2.html)

and see: http://joey711.github.io/phyloseq/tutorials-index.html

for a full list of the real tutorials.

secondary sources are sometimes misleading.

On Mon, Aug 15, 2016 at 3:35 AM, amco130 notifications@github.com wrote:

I've been going through the following tutorial:

http://genoweb.toulouse.inra.fr/~formation/15_FROGS/ April2016/R_phyloseq/phyloseq_formation_toulouse_201604.pdf

I can't perform the following (Slide 47):

p <- plot_composition(food, "Kingdom", "Bacteria", "Phylum", numberOfTaxa = 5, fill = "Phylum")

Error: could not find function "plot_composition"

I am guessing that I am missing a package but can't seem to figure out which one I need.

Any help?

amco

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/joey711/phyloseq/issues/654, or mute the thread https://github.com/notifications/unsubscribe-auth/ABJcvZkGS_6K4pJpeYCj3wsyoGEPXmzgks5qf9CAgaJpZM4JkEd6 .

Susan Holmes Professor, Statistics and BioX John Henry Samter Fellow in Undergraduate Education Sequoia Hall, 390 Serra Mall Stanford, CA 94305 http://www-stat.stanford.edu/~susan/

slvrshot commented 8 years ago

I figured out how to source the script but it's not that great of a package. Thanks!