# Humann\_barplot sort

**URL:** <https://forum.biobakery.org/t/humann-barplot-sort/2481>\
**Category:** HUMAnN\
**Created:** [August 12, 2021, 2:31am UTC](https://forum.biobakery.org/t/humann-barplot-sort/2481 "2021-08-12T02:31:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![LiuHou](https://avatars.discourse-cdn.com/v4/letter/l/6f9a4e/32.png) [@LiuHou](https://forum.biobakery.org/u/LiuHou)\
**Post date:** [August 12, 2021, 2:31am UTC](https://forum.biobakery.org/t/humann-barplot-sort/2481/1 "2021-08-12T02:31:28Z")

</div>

Hello everyone:

I am using humann\_barplot to plot my result, when I use Group as metadata for sorting, it looks like graph and the X axis would be sort by alphabetical order.

for example, my input data table is like:

 ![image](https://canada1.discourse-cdn.com/flex027/uploads/biobakery/original/1X/375a587b39f2d448fff2ec3174acfd35a1a19723.png)  
Then when i do this:  
/opt/software/miniconda3/envs/humann3/bin/humann\_barplot --input genefamilies.ko.rename.join.renorm.for\_plot.no.BC.tsv --focal-metadata Group --last-metada  
ta Group --output ./test.pdf --focal-feature K00010 --sort sum metadata --scaling logstack

The output graph is like:

 ![image](https://canada1.discourse-cdn.com/flex027/uploads/biobakery/original/1X/a353dd47b8d3b8e1d31fa4a6bab641851f066c4a.png)  
The X axis and the legend are sorted by alphabetical order, but I want: SC, L, M, and H.

Anyone knows how to solve this problem?

---

<div class="post-metadata">

**Author:** ![LiuHou](https://avatars.discourse-cdn.com/v4/letter/l/6f9a4e/32.png) [@LiuHou](https://forum.biobakery.org/u/LiuHou)\
**Post date:** [August 12, 2021, 2:35am UTC](https://forum.biobakery.org/t/humann-barplot-sort/2481/2 "2021-08-12T02:35:31Z")

</div>

I use humann\_barplot --help to see --sort options, but still I can not solve this problem, the --sort option could be provided a file: Apply sorting order read in from a file. I wonder how to use it.

---

<div class="post-metadata">

**Author:** ![LiuHou](https://avatars.discourse-cdn.com/v4/letter/l/6f9a4e/32.png) [@LiuHou](https://forum.biobakery.org/u/LiuHou)\
**Post date:** [August 12, 2021, 2:49am UTC](https://forum.biobakery.org/t/humann-barplot-sort/2481/3 "2021-08-12T02:49:39Z")

</div>

Hi, everyone, I solved this problem, by just adding a new metadata row, and group my sample as:  
A to SC, B to L, C to M, and D to H.

Then I could plot it using this new metadata as sort metadata. Finally I could get the correct order in result graph. I could modified A, B, C, D to SC, L, M ,and H using Adobe Illustrator.

Thanks to everyone.

---

<div class="post-metadata">

**Author:** ![jiakang\_yin](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/jiakang_yin/32/99_2.png) [@jiakang\_yin](https://forum.biobakery.org/u/jiakang_yin)\
**Post date:** [August 12, 2021, 3:35am UTC](https://forum.biobakery.org/t/humann-barplot-sort/2481/4 "2021-08-12T03:35:32Z")

</div>

Wow, very clever you are

---

<div class="post-metadata">

**Author:** ![franzosa](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/franzosa/32/3511_2.png) [@franzosa](https://forum.biobakery.org/u/franzosa)\
**Post date:** [August 16, 2021, 8:43pm UTC](https://forum.biobakery.org/t/humann-barplot-sort/2481/6 "2021-08-16T20:43:09Z")

</div>

I can chime in that I usually do something similar by attaching numbers to the start of the category levels to force them to obey a certain order, e.g. `0_Control`, `1_Fiber`, `2_Apples`, and so forth. This is also convenient for forcing the first group to act as the reference group in a lot of stats modeling software.

---

<div class="post-metadata">

**Author:** ![LiuHou](https://avatars.discourse-cdn.com/v4/letter/l/6f9a4e/32.png) [@LiuHou](https://forum.biobakery.org/u/LiuHou)\
**Post date:** [August 17, 2021, 4:37am UTC](https://forum.biobakery.org/t/humann-barplot-sort/2481/7 "2021-08-17T04:37:03Z")

</div>

Thank you! This wonderful software helps me a lot!
