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

Transform y axis to present between 0->100 #887

Open atarauzan opened 6 years ago

atarauzan commented 6 years ago

Hi joey Im tring to creat a nice relative abundance graph for specific genus I used thoes scrips to impost my data and creat the graph but I want that the y anix run between 0 to 100% library("phyloseq"); packageVersion("phyloseq") library("ggplot2"); packageVersion("ggplot2") theme_set(theme_bw())

dataDirectoryPath = "C:/Users/user/Documents/Atara Duc/atara/Abx- Sam (Hila)/OK69/for_R/" biomFile = "otu_table_allmonth_withtaxonomy.biom" fullInputPath = file.path(dataDirectoryPath, biomFile) fullInputPath file.exists(fullInputPath) file.info(fullInputPath)

biom1 = biomformat::read_biom(biom_file = fullInputPath) names(biom1) mp0 <- import_biom ("C:/Users/user/Documents/Atara Duc/atara/Abx- Sam (Hila)/OK69/for_R/new_otu_table_bifi.biom", parseFunction = parse_taxonomy_greengenes)

tax_table(mp0) <- tax_table(mp0)[, 1:7] rank_names(mp0) mp0

qsd = import_qiime_sample_data("C:/Users/user/Documents/Atara Duc/atara/Abx- Sam (Hila)/OK69/for_R/mapping_file_ok69_abx__UPDATE_090817.tsv") mp1 = merge_phyloseq(mp0, qsd) mp1 sample_variables(mp1)

treeFile1 = "C:/Users/user/Documents/Atara Duc/atara/Abx- Sam (Hila)/OK69/for_R/tree.nwk" tree1 = read_tree(treeFile1) tree1 class(tree1)

Add to the data object

mp2 = merge_phyloseq(mp1, tree1) mp2

repseqFile = "C:/Users/user/Documents/Atara Duc/atara/Abx- Sam (Hila)/OK69/for_R/dna-sequences.fasta" bs1 = Biostrings::readDNAStringSet(repseqFile)

Remove non-OTU information from sequence name

names(bs1) <- gsub("\s.+$", "", names(bs1)) sum(names(bs1) %in% taxa_names(mp2))

Add to the data object

mp3 = merge_phyloseq(mp2, bs1) mp3

Easier without loop

saveRDS(mp2, "mp-phyloseq-lab.RDS")

Define object names

mpObjNames = paste0("mp", 0:3)

Define list of the different stages of our object build

mpList = mget(mpObjNames)

Use mapply() function to loop over each object

mapply("saveRDS", mpList, paste0("mp", 0:3, ".RDS"), SIMPLIFY = TRUE) save(list = paste0("mp", 0:3), file = "myObjList.RData") ps = readRDS("mp-phyloseq-lab.RDS") ps

gp.ch = subset_taxa(ps, Genus == "Bifidobacterium") p <- plot_bar(gp.ch, x = "TreatGroup" , fill = "Species") + geom_bar(stat = "identity") + scale_x_discrete("TreatGroup", limits = c("1.Abx_Treatment", "1.Control","6.Abx_Treatment", "6.Control","12.Abx_Treatment", "12.Control","24.Abx_Treatment", "24.Control")) p

Thank you very much Atara rplot01 rplot01

atarauzan commented 6 years ago

I tried the ps3ra = transform_sample_counts(ps, function(x){x / sum(x)}) but it doesn't help :-( rplot02

chelseajkc commented 6 years ago

I am also struggling with this. There is this tutorial http://joey711.github.io/phyloseq-demo/Restroom-Biogeography that has been referenced for the issue in the past. There is a section where you merge samples and this is meant to bring the total to 100, however when I perform that command, it pulls out my variable column of interest and won't repair it with the repair code. Any help on either of these issues would be much appreciated.

Chelsea