I am using seaborn to create a stripplot for three conditions. The example data look like:
df = pd.DataFrame(
{
'bill': [50, 45, 33, 23, 22, 34, 54, 22, 54, 76],
'day': ['sat', 'sat', 'sat', 'sat', 'sat', 'sun', 'sun', 'sun', 'sun', 'sun'],
'tip': ['yes', 'no', 'yes', 'no', 'yes', 'no', 'yes', 'no', 'yes', 'no']
}
)
The seaborn plot:
sns.stripplot(x='day', y='bill', data=df, jitter=True, hue='tip', palette='deep', dodge=True)
How can I plot a point in each category that signifies the mean of that category?
I have tried adapting this [code][1] , but this created average for day but not separate averages for day/tip.
Thanks in advance!
[1]: https://stackoverflow.com/questions/67481900/how-to-add-a-mean-line-to-a-seaborn-stripplot-or-swarmplot#:~:text=import%20seaborn%20as,p)%0Aplt.show()
>Solution :
Maybe overlay a pointplot?
import seaborn as sns
sns.stripplot(x='day', y='bill', data=df, jitter=True, hue='tip', palette='deep', dodge=True)
sns.pointplot(x='day', y='bill', data=df, hue='tip', palette='deep', dodge=True, linestyles='', errorbar=None)
Output:
You can cheat a bit to have a more meaningful legend:
import seaborn as sns
sns.stripplot(x='day', y='bill', data=df, jitter=True, hue='tip', palette='deep', dodge=True)
sns.pointplot(x='day', y='bill', data=df.assign(tip=df['tip']+' (avg)'),
hue='tip', palette='deep',
dodge=True, linestyles='', errorbar=None)

