Sometimes we’ll want to aggregate our data by multiple columns to visualize nested categorical variables.
For example, consider our hospital survey data. The mean satisfaction seems to depend on
Gender, but it might also depend on another column:
We can compare both the
Age Range factors at once by using the keyword
sns.barplot(data=df, x="Gender", y="Response", hue="Age Range")
hue parameter adds a nested categorical variable to the plot.
Notice that we keep the same x-labels, but we now have different color bars representing each
Age Range. We can compare two bars of the same color to see how patients with the same
Age Range, but different
Gender rated the survey.
sns.barplot() to create a chart with:
How is this plot different from when
"Age Range" and
Why might we use one and not the other?
plt.show() to display the graph.