Comments (5)
Yes, statannotations works well with the hue argument in FacetGrid too but pairs are defined at plot level, so the x
and hue
should be the same across plots, which is not the case for you here.
The "today" solution for you would perhaps be to define subplots to create your desired layout and then use the "regular" plot + stannanotations on each subplot as you'll have different pairs to compare in each one.
(See this post https://www.statology.org/seaborn-subplots/)
Something like this:
annot = Annotator.get_empty_annotator()
plot_params = {
'x':'receptor',
'y':'expression',
'hue':'roi',
'hue_order':['roi','non-roi'],
}
receptor_groups = expression_long['receptor_group'].unique()
sns.color_palette("Paired")
with sns.plotting_context("paper"):
fig, axes = plt.subplots(4, 2, figsize=(20, 30))
for ax_row_idx, ax_row in enumerate(axes):
for ax_col_idx, ax in enumerate(ax_row):
ax_idx = ax_row_idx * 2 + ax_col_idx
if ax_idx >= len(receptor_groups):
ax.set_axis_off()
continue
ax_group = receptor_groups[ax_idx]
expression_long_group = expression_long.loc[expression_long.receptor_group==ax_group, :]
group_receptors = expression_long_group['receptor'].unique()
sns.boxplot(ax=ax, data=expression_long_group, **plot_params)
annot.new_plot(
ax,
data=expression_long_group,
pairs=[((receptor,'roi'),(receptor,'non-roi')) for receptor in group_receptors],
plot='boxplot',
**plot_params
).configure(test="Mann-Whitney").apply_and_annotate()
ax.set_title(ax_group)
if len(group_receptors) > 10:
ax.set_xticklabels(labels=ax.get_xticklabels(), rotation=45)
plt.show()
Which results in this approximation of your diagram :) Tweaking spacing and legends, groups ordering, maybe using the last row for your larger group (look for add_subplot
) should enable you to get there though.
from statannotations.
Perfect, thanks so much for the code! Then only issue that I see right now, is that the multiple comparisons correction is now done within each group and not over all receptors right?
from statannotations.
Of course!
This is correct, but it is also the case with plot_and_annotate_facet
(I should make that clearer).
Depending on the correction method, you can fix this by either
- passing a
num_comparisons
option (like for Bonferonni) or - running the stats beforehand and then use set_pvalues instead on each subplot.
In that case, you'll have to- Compute all the pairs you use in the plots
- Plot a chart with receptors of all groups, but using the pairs described above
- Collect the pvalues for each pair
- Use these when you're making the "real" plot as drafted above.
from statannotations.
This is correct, but it is also the case with plot_and_annotate_facet (I should make that clearer).
Ah, interesting! Yes, I think making that clearer would help a lot :)
passing a num_comparisons option (like for Bonferonni)
That sounds like a good idea, but would only work for methods, that do not need to know all the p-values before-hand right?
from statannotations.
Of course!
This is correct, but it is also the case with
plot_and_annotate_facet
(I should make that clearer).Depending on the correction method, you can fix this by either
passing a
num_comparisons
option (like for Bonferonni) orrunning the stats beforehand and then use set_pvalues instead on each subplot.
In that case, you'll have to
- Compute all the pairs you use in the plots
- Plot a chart with receptors of all groups, but using the pairs described above
- Collect the pvalues for each pair
- Use these when you're making the "real" plot as drafted above.
Would love if this would work out-of-the-box! The general idea here is that you often want to plot stuff using facet_grid for better readability but you don't want the multiple comparison to be done within each subplot.
from statannotations.
Related Issues (20)
- Drifting annotations with FacetGrid HOT 1
- Get results as pandas dataframe?
- What does * (ns) mean? HOT 3
- report corrected p values
- Integration with new Numpy and Seaborn? HOT 1
- Seaborn categorical plot issue HOT 1
- Possible to not show non-significant relationships? HOT 1
- Feature request: Text format that combines both numerical p-values and stars
- Possible to get statistics and p-values when using FacetGrid?
- How to keep two decimal places with text_format='full' HOT 1
- v0.60 not compatible with seaborn v0.13 HOT 6
- Add ANOVA?
- Feature request: Lineplot support
- Customize Annotations HOT 1
- Adding Tutorials to documentation site
- Use src/ folder for package
- Offset the significance brackets
- Feature request: permutation test
- Getting rid of minor tick marks
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from statannotations.