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/
582 stars 187 forks source link

Is there a way to display unstacked relative abundance using faceting? #679

Open slvrshot opened 8 years ago

slvrshot commented 8 years ago

For example, my current code displays the absolute abundance of taxa beautifully using faceting. Here is a sample the code:

GPr = transform_sample_counts(testdata, function(x) x / sum(x) )
GPr
GPfr = filter_taxa(GPr, function(x) mean(x) > 1e-5, TRUE)
GPfr
colnames(tax_table(GPfr))= c("Kingdom","Phylum","Class","Order","Family","Genus","Species")
rank_names(GPfr)
TopNOTUs <- names(sort(taxa_sums(GPfr), TRUE)[1:1000])
ent10 <- prune_taxa(TopNOTUs, GPfr)
ent10

p = plot_bar(ent10,"Phylum", fill="Phylum", facet_grid=Gut_Location~Description) #best plots
p + geom_bar(aes(color=Phylum, fill=Phylum), stat="identity", position="stack")

On the Y axis I want it to go from (0,100)....and plot the relative abundance of each taxa on the X axis....so if Bacteroidetes makes up 30% of the reads I would like it to plot up to 30% on the Y axis...and if Firmicutes make up 60% I would like a bar beside Bacteroidetes indicating it contributes 60% of the reads, etc etc. I hope this makes sense.

Please help!

test_pic

slvrshot commented 7 years ago

Hi Joey I lost some code for this and was hoping you may have some idea to make this easier. I know it involves repairing factors, and transforming counts to proportions, but some of my original code when I originally got it to work is missing (not sure what happened).

Thanks!