trevismd / statannotations

add statistical significance annotations on seaborn plots. Further development of statannot, with bugfixes, new features, and a different API.
Other
619 stars 67 forks source link

boxplot with hue: annot. not correctly lining up #103

Closed xqqe closed 1 year ago

xqqe commented 1 year ago

In this graph, the annotations are supposed to go from pink (LN) to pink, but they only go from green (HN) to green and I can't figure out what's wrong. I've attached the image and the code I used for this particular graph below.

chrome_kclDjlW4mf

order = list(set(df['Genotype']))
order.sort()
pairs = [[('A3GK', 'LN'), ('COL', 'LN')], [('COL', 'LN'), ('GV5', 'LN')]]
hue_order = ['NN','HN','LN']

plot_params = {
    'data': df,
    'x': 'Genotype',
    'y': 'PR_Length',
    "order": order,
    "hue": 'Condition'}

plot = sns.boxplot(**plot_params,hue_order = hue_order)

annotator = Annotator(plot, pairs, **plot_params)
annotator.configure(test='Mann-Whitney', verbose=1)
annotator.apply_test()
annotator.annotate()
sns.move_legend(plot, "upper left", bbox_to_anchor=(1, 1))
plt.show()
trevismd commented 1 year ago

Hello, It looks like you kept hue_order out of plot_params, and passed it to sns.boxplot but not to Annotator.

trevismd commented 1 year ago

Was that it?

xqqe commented 1 year ago

I think it was. Thanks for your help and for following up.