Ordering Categorical Variable in Gneiss

Hi,

I am using Gneiss to detect differential abundance of taxa in many nominal categories of a categorical variable. The summary plots, for example, of 'y0', put the categories on the y-axis in an order that does make sense. Is there a way to specify the order of the categories?

The order should be C1, C2, C3, C4, C5, Cc, Cn, Ca, S1, S2, S3, S4, S5, Ss, Sr, Sa.

Thank you,
Noah

Hi @noah. I’m glad that you are seeing strong signals here!

Considering figures, the qiime2 plugin for Gneiss is not meant to give out of the box publishable figures. To fine tune the plots, I’d recommend taking a look at the Gneiss Python API. There is a python function called balance_boxplot that gives fine-tune control over these sorts of operations.

Let me know how far you get - I’ll be happy to answer any questions.

Hi Jamie,

This is my first time using Python, so I do not know exactly what I am doing. I did get the commands to work. I just don’t know how to view the plot. Is there a way to export balance boxplots and other sorts of plots from gneiss so that they can be easily viewed?

Here are the last commands I typed.

ax = balance_boxplot(‘y0’, data, y=‘Seq’, num_color=’#FFF4AF’, denom_color=’#AFFFC5’, palette={‘C1’: ‘orange’, ‘C2’: ‘palegreen’, ‘C3’: ‘orange’, ‘C4’: ‘palegreen’, ‘C5’: ‘orange’, ‘Cc’: ‘palegreen’, ‘Cn’: ‘orange’, ‘Ca’: ‘palegreen’, ‘S1’: ‘orange’, ‘S2’: ‘palegreen’, ‘S3’: ‘orange’, ‘S4’: ‘palegreen’, ‘S5’: ‘orange’, ‘Ss’: ‘palegreen’, ‘Sr’: ‘orange’, ‘Sa’: ‘palegreen’})
ax
<matplotlib.axes._subplots.AxesSubplot object at 0x7fde29735e10>

Thanks,
Noah

Hi @noah! Since this question is veering a ways away from QIIME 2, you might be better off consulting the gneiss support channels (@mortonjt can chime on that), or the matplotlib/seaborn docs or support channels. That said, you should be able to save that by calling savefig (YMMV)

ax.savefig("my_balance_boxplot.png") 

If that doesn’t work you could try:

ax.get_figure().savefig("my_balance_boxlplot.png")

If those options don’t work, I would suggest checking in with the seaborn or matplotlib support forums. Thanks!

1 Like

Along those lines, gneiss does have a gitter channel. I’ll be happy to follow up with gneiss specific questions there.

1 Like

Hi,

ax.get_figure().savefig(“my_balance_boxlplot.png”) did the trick. Also, I figured out that to display the metadata categories in the correct order, I had to re-order them in my metadata file and specify how = ‘right’ in the pd.merge command.

data = pd.merge(balances, metadata, left_index=True, right_index=True, how=‘right’)

Thanks,
Noah

1 Like

Hi Jamie,

I just posted a new question in your gitter channel.

Thanks,
Noah

1 Like

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.