Open Shrulik opened 2 years ago
I did it like this:
col_df = "ball height"
row_df = 'scenario'
x = 'light type'
hue = 'occluder type' #just column names of the dataframe
comp_pairs = [((data_df[x].unique()[0],data_df[hue].unique()[0]), (data_df[x].unique()[1],data_df[hue].unique()[0])),
((data_df[x].unique()[0],data_df[hue].unique()[1]), (data_df[x].unique()[1],data_df[hue].unique()[1])),
((data_df[x].unique()[0],data_df[hue].unique()[0]), (data_df[x].unique()[0],data_df[hue].unique()[1])),
((data_df[x].unique()[1],data_df[hue].unique()[0]), (data_df[x].unique()[1],data_df[hue].unique()[1]))]
for i,ax in g.axes_dict.items():
annotator = Annotator(ax=ax, pairs=comp_pairs, **fig_args, plot='stripplot', data=data_df[(data_df[row_df] == i[0]) & (data_df[col_df]==i[1])])
annotator.configure(**configuration).apply_test().annotate()
Thanks for the great tool...
Original seaborn catplot code (my data is a catplot of grouped box plots (2 boxplots each group)):
g = sns.catplot(x='age_group', y="expression", height=2, aspect=0.8, hue="treatment", palette=treatment_color[0],treatment_color[-1]],
kind="box", data=dat2plot, col='gene',col_wrap=5, width=0.7 ,sharey=False,
flierprops={'marker': 'o', 'markersize': 3, 'markerfacecolor': 'gray',
'markeredgewidth':None, 'markeredgecolor':None, 'alpha':.2},
);
Same output with statistics on (you need to add a line for the legend as it was missing for me):
from statannotations.Annotator import Annotator
annot = Annotator(None, pairs)
plot_params = {
'x':'age_group',
'y':'expression',
'hue':'treatment',
'palette':[treatment_color[0], treatment_color[-1]],
'flierprops':{'marker': 'o', 'markersize': 3, 'markerfacecolor': 'gray',
'markeredgewidth':None, 'markeredgecolor':None, 'alpha':.2},
}
g = sns.FacetGrid(dat2plot, col='gene', height=2, aspect=0.8, sharey=False, col_wrap=5)
g.map_dataframe(annot.plot_and_annotate_facets, plot='boxplot',
plot_params=plot_params,
configuration={"test": "Mann-Whitney", "verbose":False, 'line_width':0.75, 'line_offset_to_group':0},
annotation_func="apply_test",
)
g.add_legend(title='treatment')
Is there support planned ?
Is it possible to make the current version work with catplot if I work with the FacetGrid that is returned from the sns.catplot ?
For example, maybe passing a function to g.map_dataframe and for each axis to do the annotations ?