Search code examples
pythonpandasseabornswarmplot

Make sns.swarmplot with respect to two categorical variables in x-axis


I have a pandas DataFrame and, I could make a sex-age swarm plot (picture have two columns male and female). and also diabetes-age swarm plot (two columns yes and no)

How could I make a swarm plot with four columns:

male&yes male&no female&yes female&no


Solution

  • You could use the hue parameter of sbn.swarmplot:

    g = sbn.swarmplot(x="Gender", y="Age", hue="Diabetes", data=data, dodge=True, size=10)
    

    This gives:

    enter image description here