0

I am creating graphs with Fantaxtic for phyloseq. I am creating graphs from the same data in two ways.

Grouping samples by month: I need to display the months in chronological order, not alphabetical. I tried to set the orders of the months as such but it still is in alphabetical order in the plot.

sample_data(ps)$Month = factor(sample_data(ps)$Month, 
                                         levels = c("Nov 2020","Apr 2021","May 2021","Jul 2021", "Feb 2022", "Mar 2022", "Apr 2022"))

ps_norm <- transform_sample_counts(ps, function(x) x / sum(x) )
top_order <- top_taxa(ps_norm, n_taxa = 15, tax_level = "Order")

plot_nested_bar(top_order$ps_obj,
                top_level = "Phylum",
                nested_level = "Order") +
  facet_wrap(~Month_2,
             scales = "free_x")

enter image description here

Grouping by location: I need to display sample names in numerical order. R is interpreting 900 as larger than 1000 due to the first digit.

enter image description here

Gregor Thomas
  • 136,190
  • 20
  • 167
  • 294
MAlvarez
  • 31
  • 5
  • I'm not familiar with `phyloseq`, but it seems suspect to me that the data you change the levels of is `sample_data(ps)$Month`, and then you transform it and extract top counts before plotting `top_order`. Can you inspect the `Month` column of `top_order` and verify it has levels in the correct order, and if not correct it there? – Gregor Thomas Apr 26 '23 at 01:31

1 Answers1

0

I am the author of fantaxtic. Unfortunately, information about order of the levels in the data is lost when psmelt is called. However, you can easily change the order of your facets in your call to facet_grid or facet_wrap; see this example. I hope that resolves your issue.

In the future, feel free to submit these questions/issues directly to the fantaxtic repository on github so that I can quickly resolve your issues.

gmt
  • 325
  • 1
  • 7