Closed HamishForrest closed 2 years ago
Hello, It does work fine but it may not be clear how without demo. Here is one based on your example (with fake data of course):
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
from statannotations.Annotator import Annotator
data = [
{"Age": 5, "Sex": "F", "value": 3},
{"Age": 5, "Sex": "F", "value": 8},
{"Age": 5, "Sex": "F", "value": 6},
{"Age": 8, "Sex": "F", "value": 4},
{"Age": 8, "Sex": "F", "value": 11},
{"Age": 8, "Sex": "F", "value": 14},
{"Age": 8, "Sex": "M", "value": 10},
{"Age": 5, "Sex": "M", "value": 3},
{"Age": 5, "Sex": "M", "value": 3},
{"Age": 5, "Sex": "M", "value": 9},
{"Age": 8, "Sex": "M", "value": 12},
{"Age": 5, "Sex": "O", "value": 8},
{"Age": 5, "Sex": "O", "value": 8},
{"Age": 5, "Sex": "O", "value": 6},
{"Age": 8, "Sex": "O", "value": 6},
{"Age": 8, "Sex": "O", "value": 3},
{"Age": 8, "Sex": "O", "value": 2},
]
data = pd.DataFrame(data)
plot_params = {
"x": "Age",
"y": "value",
"hue": "Sex",
"data": data
}
ax = sns.boxplot(**plot_params)
pairs = [
[(5, "M"), (5, "F")],
[(5, "F"), (5, "O")],
[(8, "M"), (8, "O")],
]
p_values = [0.1, 0.2, 0.001]
annot = Annotator(ax=ax, pairs=pairs, **plot_params)
annot.configure(loc='outside').set_pvalues_and_annotate(p_values)
plt.savefig('example_hue_custom.png', dpi=300, bbox_inches='tight')
Which makes
@HamishForrest, I'm closing this but please do not hesitate to comment if something isn't clear.
Thanks for your help! Your solution worked great.
Happy continue using this repository it has been really useful.
Hi,
It seems likeadding custom (manual) p_values for box plot with hue is not possible. I cannot see an example of it anywhere and it would be very useful please! Thanks!
I guess it would look something like: