gmteunisse / fantaxtic

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

How can I group samples by fixed effects on the x axis instead of the model? #22

Closed jjhackma closed 11 months ago

jjhackma commented 11 months ago

ecto samples

In the below code: I'm using a phyloseq object ecto. I want to have the x-axis separated by a fixed effect, "soil type" between soil 1 and soil 2. So instead of individual samples on the x axis, which is shown in all your examples, I want the taxa grouped into a single column for either soil 1 or soil 2.

is there anyway to do that? I'm a total noob to this type of data so I'm at a loss.

top_nestedspod <- nested_top_taxa(ecto, top_tax_level = "phylum", nested_tax_level = "genus", n_top_taxa = 6, n_nested_taxa = 6)

plot_nested_bar(ps_obj = top_nestedspod$ps_obj, top_level = "phylum", nested_level = "genus", nested_merged_label = "NA and other", legend_title = "Phylum and Genus")+ facet_wrap(~Carryover, scales = "free_x") + theme(plot.title = element_text(hjust = 0.5, size = 8, face = "bold"), legend.key.size = unit(10,"points"))

I'm getting a nice output, but I really want the mean grouping of each fixed effect on the x axis (soil type). I found your "grouping" section in the READme file, but I'm not seeing how to incorporate anything into the above code.

image

gmteunisse commented 11 months ago

Can you clarify what you mean by a single column? Do you mean a single bar per group, or a single facet per group?


From: jjhackma @.> Sent: Wednesday, August 9, 2023 2:07:52 AM To: gmteunisse/fantaxtic @.> Cc: Subscribed @.***> Subject: [gmteunisse/fantaxtic] How can I group samples by fixed effects on the x axis instead of the model? (Issue #22)

spodosolpost samples

In the below code: I'm using a phyloseq object ecto. I want to have the x-axis separated by a fixed effect, "soil type" between soil 1 and soil 2. So instead of individual samples on the x axis, which is shown in all your examples, I want the taxa grouped into a single column for either soil 1 or soil 2.

is there anyway to do that?

top_nestedspod <- nested_top_taxa(ecto, top_tax_level = "phylum", nested_tax_level = "genus", n_top_taxa = 6, n_nested_taxa = 6)

Plot the relative abundances at two levels.

plot_nested_bar(ps_obj = top_nestedspod$ps_obj, top_level = "phylum", nested_level = "genus", nested_merged_label = "NA and other", legend_title = "Phylum and Genus")+ facet_wrap(~Carryover, scales = "free_x") + theme(plot.title = element_text(hjust = 0.5, size = 8, face = "bold"), legend.key.size = unit(10,"points"))

Any help would be appreciated, I'm racking my brains over this.

— Reply to this email directly, view it on GitHubhttps://github.com/gmteunisse/fantaxtic/issues/22, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AHBWS3SKANSWKSAGKTEE5FTXULIFRANCNFSM6AAAAAA3JGTVAI. You are receiving this because you are subscribed to this thread.Message ID: @.***>

jjhackma commented 11 months ago

A single bar with all the samples grouped together by individual facets is what I'm after.

So from the below image, I just want a single bar with the mean abundances of all the taxa in that facet. image

I want the taxa from each sample to be grouped by my a treatment effect from my metadata in my phyloseq object to look like this image

gmteunisse commented 11 months ago

Thanks for the clarification. I have to disappoint you: this option is not available in Fantaxtic, and I'm also not planning on making it available. The grouping argument that you refer to is only used select the top taxa, e.g. what are the top 3 taxa by mean abundance per group. If you want to create a single bar per group, you will need to aggregate the abundances in the resulting phyloseq object by group manually, for example using the merge_samples function in phyloseq. Make sure to normalise (e.g. sum-scale) your abundances before you do so. After the aggregation, you can still use fantaxtic to plot the resulting phyloseq object.

One of the downsides of only displaying the mean abundance per taxon per group is that you lose information about the variance in abundance. I would suggest to use box-plots instead, which can display some measure of centrality, as well as a measure of dispersion. In the Fantaxtic documentation, I've created an example of how to create these plots using fantaxtic and it's core plotting package ggnested. Have a look at the example here: https://github.com/gmteunisse/fantaxtic#alternative-plot-types. Make sure to follow along with the preliminary processing steps in the Advanced usage section. For your desired plot, you can use your fixed effect on the x-axis.

I hope that this helps you create the visualisation you're looking for. Good luck!