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/
579 stars 188 forks source link

plot_bar function #882

Open aiali0419 opened 6 years ago

aiali0419 commented 6 years ago

I'm having issues ordering the bars in the plot_bar function. I've tried using levels, but it doesn't seem to change the location of the samples in the graph. I want the different treatments (denoted by tank in my variable table) to be clustered together, instead of how they are dispersed.

Here is the code that I am using:

`samdf<-read.csv("variabletables.csv")

head(samdf)

rownames(samdf) <- samdf$tank

ps <- phyloseq(otu_table(seqtab.nochim, taxa_are_rows=FALSE), 
               sample_data(samdf), 
               tax_table(taxa))

sample_data(ps)$Sample <- factor(sample_data(ps)$Sample, levels=c("hostsed", "sed", "host", "DIP", "FAV"))

top30 <- names(sort(taxa_sums(ps), decreasing=TRUE))[1:50]

ps.top30 <- transform_sample_counts(ps, function(OTU) OTU/sum(OTU))

ps.top30 <- prune_taxa(top30, ps.top30)

plot_bar(ps.top30, x="Sample", fill="Class") + facet_wrap("tank")`

bar plot with the treatments

mikemc commented 6 years ago

Try

plot_bar(ps.top30, x="Sample", fill="Class")
    + facet_wrap(~tank, space="free", scales="free")

or

plot_bar(ps.top30, x="Sample", fill="Class")
    + facet_wrap("tank", space="free", scales="free")

(either should work).