0

This is the code for how I have been separating out the top 10 orders in the data set to graph relative abundance. How could I include the top 10 orders + an 11th group called others with the remaining data to have my stacked bars fill up to 100%?

order.sum = tapply(taxa_sums(relabun), tax_table(relabun)[, "Order"], sum, na.rm=TRUE) top10orders = names(sort(order.sum, TRUE))[1:10] ps2 = prune_taxa((tax_table(relabun)[, "Order"] %in% top10orders), relabun) ps_top10orders <- tax_glom(ps2,taxrank = "Order") ps_top10orders<-transform_sample_counts(ps_top10orders,function(x) x / sum(x)) ps_top10orders<-psmelt(ps_top10orders) ps_top10orders<-arrange(ps_top10orders,Order)

Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
  • Have you considered `forcats::fct_lump_n()` or `forcats::fct_lump_prop()`? – teunbrand Apr 12 '21 at 16:48
  • Yes, so I can view the tables with that, how do I use it to prune my data into a top 10 + others? What would the line of code look like? It would have to come after I take relabun? – Jacob Coppolino Apr 12 '21 at 18:06
  • I don't know the structure of your data, so I can't advice you on that. Generally speaking, the quality of answers you get on SO depend on how well people can reproduce the problem you are having. See [this guide](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) for how to ask questions people can help you with. – teunbrand Apr 12 '21 at 18:29

0 Answers0