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

Problem with plot_bar #360

Closed balaTHLkuopio closed 10 years ago

balaTHLkuopio commented 10 years ago

image

Hi,

I am having problems while plot the taxa where all the genus having same colors as you can see from the above figure. Below is my code that i used:

otufile <- system.file("extdata", "otu_table_bootstrap_with_taxa_new.txt", package="phyloseq") mapfile <- system.file("extdata", "mapping_file_bootstrap.txt", package="phyloseq") test <- import_qiime(otufile, mapfile) top19otus = names(sort(taxa_sums(test), TRUE)) taxtab19 = cbind(tax_table(test), family19 = NA) taxtab19[top19otus, "family19"] <- as(tax_table(test)[top19otus, "Genus"],"character") tax_table(test) <- tax_table(taxtab19) title = "Figure 1 attempt 1" plot_bar(test, fill = "family19", title = title) + coord_flip() test = transform_sample_counts(test, function(x) 100 * x/sum(x)) title = "Figure 1 Part A (remake), attempt 2" plot_bar(test, fill = "family19", title = title) + coord_flip() + ylab("Percentage of Sequences") test = prune_taxa(top19otus, test) title = "Figure 1 Part A (remake), attempt 3" plot_bar(test, fill = "family19", title = title) + coord_flip() + ylab("Percentage of Sequences") + ylim(0, 100)

version details: [1] ggplot2_0.9.3.1 phyloseq_1.8.1 R 3.1.0

Please let me know what is the problem. I can also send the otu table to your email ID personally if needed.

Thanks in advance.

Best Regards, Bala

joey711 commented 10 years ago

You have way too many genera in that dataset to be worth plotting them all with different colors. Try a higher taxonomic rank. Something earlier in the vector returned by rank_names(test).

If you look carefully, you can see that the color shade is actually changing, slightly, for each genus visible in the legend.

You may want to review R and phyloseq documentation a bit further. This appears to be cut and pasted from the "Restroom Biogeography" tutorial with little concern for context.

balaTHLkuopio commented 10 years ago

Thanks for your reply joey...I will look into it..Could you also please suggest how to fit all the legends in the window as some of them just jumps out of the window. I am kind of very new to R and phyloseq. Sorry if it is very obvious

joey711 commented 10 years ago

They don't jump out of the window if you select a category, perhaps Phylum, that has a reasonable number of classes in it. In most instances you only want to be mapping 9 or 10 different classes to a particular color in a graphic. Any more than that is getting very unreasonable / impossible for the human eye to distinguish. You dataset is diverse enough at the Genus level, that it doesn't make sense to set color="Genus" or family, etc. Hopefully Phylum works. If not, you can also facet by Genus, or map Genus to the x-axis. There are lots of options, but you will need to do some reading to understand what they are. The tutorials demonstrate a lot of this. Please give them some more careful review, as well as ggplot2 package documentation.