gmteunisse / fantaxtic

Fantaxtic - Nested Bar Plots for Phyloseq Data
26 stars 3 forks source link

plot_nested_bar: Specify colors for each bacterial order #17

Closed pauGuas closed 1 year ago

pauGuas commented 1 year ago

Hello, I need to specify colors for each of my bacterial orders so I can compare across plots. I tried using this code but the plot comes up with randomly chosen colors by the program. Could you help me troubleshoot? Thank you!

ps <- GlobalPatterns ps_norm <- transform_sample_counts(ps, function(x) x / sum(x) ) order <- tax_glom(ps_norm, taxrank = "Order") top_order <- top_taxa(order, n_taxa = 15) plot_nested_bar(ps_obj = top_order$ps_obj, top_level = "Phylum", nested_level = "Family", palette=c(Frankiales = "paleturquoise1", Micrococcales = "turquoise2", Microtrichales = "turquoise3", Bacteroidales = "gold", Cytophagales = "goldenrod2", Flavobacteriales = "goldenrod3", Burkholderiales = "mistyrose", Enterobacterales = "pink", Pseudomonadales = "palevioletred1", Rhizobiales = "palevioletred3", Sphingmonadales = "maroon1", Rhodobacterales = "violetred4", Xanthomonadales = "palevioletred4", Verrucomicrobiota = "black"))

gmteunisse commented 1 year ago

Hi Pau,

There are two reasons why you are not getting the colours that you're specifying:

  1. None of the top 15 orders match the names that you provided in palette.
  2. You specified top_level="Phylum", so the colouring is by phylum, not by order.

Some other observations:

  1. It is not necessary to make the sample counts proportional, fantaxtic does this automatically (unless by_proportion=FALSE)
  2. It is not necessary to agglomerate your data before running the function - you can specify top_taxa(ps, n_taxa=15, tax_level='Order') to get to the same result
  3. You use nested_level=Family, even though you are agglomerated at the order level, so there is no information at the family level.

See below for a reproducible example. Also have a look at the documentation on the main page and for each function using help(top_taxa); help(nested_top_taxa); help(plot_nested_bar).

require('phyloseq')
#> Loading required package: phyloseq
require('fantaxtic')
#> Loading required package: fantaxtic

data("GlobalPatterns")

ps <- GlobalPatterns
top_order <- top_taxa(ps, n_taxa = 15, tax_level = 'Order')
plot_nested_bar(ps_obj = top_order$ps_obj, top_level = "Phylum",
                nested_level = "Order",
                palette=c(Actinobacteria = 'blue',
                          Bacteroidetes = 'green',
                          Cyanobacteria = 'red',
                          Firmicutes = 'turquoise',
                          Proteobacteria = 'purple'))

Created on 2023-04-19 by the reprex package (v2.0.1)

gmteunisse commented 1 year ago

Glad you’re getting closer! You have to supply a character vector with the sample names in the desired order to ‘sample_order’. Check out the example in the documentation.


From: Pau Fiori @.> Sent: Tuesday, April 25, 2023 11:50:27 PM To: gmteunisse/fantaxtic @.> Cc: gmteunisse @.>; Comment @.> Subject: Re: [gmteunisse/fantaxtic] plot_nested_bar: Specify colors for each bacterial order (Issue #17)

I am so close to getting this graph how I want it! My samples have numbers as the sample_names. I made sure they are as.numeric. Still, the graph does not put them in numerical order on the X axis.

[image]https://user-images.githubusercontent.com/84878533/234411990-c4544fea-8e05-4cdd-aed6-3dcd26cde979.png

— Reply to this email directly, view it on GitHubhttps://github.com/gmteunisse/fantaxtic/issues/17#issuecomment-1522465083, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AHBWS3XIUTVBWCMN6OSO7IDXDBBKHANCNFSM6AAAAAAXCZ77NE. You are receiving this because you commented.Message ID: @.***>