I want to plot a histogram of percentages using displot
in seaborn (version 0.12.0), which creates a FacetGrid of subplots. Percentages should be separately calculate for each subplot. In general, one can achieve this using the parameter common_norm=False
. However, when also adding a hue to the plot, the common_norm also affects the hue categories, which I do not want, because it results in bins summing up to more than 100% within one subplot:
You can use this to reproduce the figure:
sns.displot(data=sns.load_dataset("tips"), x="tip", col="smoker", row="time", hue="sex", common_norm=False, common_bins=False, facet_kws=dict(margin_titles=True, sharey="row"), stat="percent")
My expected behaviour would be that all the bins within one subplot sum up to 100%.
Is there a way to disable the common_norm on the FacetGrid subplot level, but not on the hue-level?
@JohanC: I could not find anything on what common_norm
should specifically affect, which is why I asked this question, but it does not do what you say:
sns.displot(data=sns.load_dataset("tips"), x="tip", col="smoker", row="time", hue="sex", common_norm=True, common_bins=False, facet_kws=dict(margin_titles=True), stat="percent")
When setting common_norm=True
, now the values over the whole FacetGrid sum up to 100%.