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

How to export the relative abundance of specific phylum? #1299

Open brightyoni opened 4 years ago

brightyoni commented 4 years ago

Hi, I am newly started to facilitate the data with R. I have some basic questions. I searched the similar questions to mine, but I failed to solve it. Your response will be great help to me. Firstly, I tried to analyze the relative abundance about each phylum and expressed into bar plot. Next thing what I want is export the exact percentage of specific phylum from each sample to Excel or text file, but I didn't make it. Here is my code to analyze the sample.

ps <- phyloseq(otu_table(matrix,taxa_are_rows=TRUE), sample_data(cond), tax_table(as.matrix(taxa))) ps_1 <- transform_sample_counts(ps,function(otu) otu/sum(otu)) plot_bar(ps_1, fill="Phylum") + geom_bar(aes(color=Phylum, fill=Phylum), stat="identity", position="stack")

I would like to export the relative percentage of "Bacteroidetes" from ps_1 data. How should I do?

ParrMcQueen commented 4 years ago

I am also looking to see if there is a built in way to do this within phyloseq. I wrote R code to subset the OTU table to only include ASVs that have a specific taxonomy and then use colSums. But it would be great if there was a quick way to export the exact values that are plotted based on the color= and fill= inputs.