2

I am trying to make a swam plot that contains more information than a single categorical level and two variables. I am looking to create something like this swarm

So ideally, something like this would work (but it does not):

ax = sns.swarmplot(x="round_id", y="independent_error_abs", hue="difficulty", hue_order=['easy','medium','hard'], size="followers", markershape="rank",data=df)

where "difficulty", "followers", and "rank" determine the color of the point, the size of the point, and the shape of the point, respectively.

amaatouq
  • 2,297
  • 5
  • 29
  • 50

2 Answers2

0

No, this is not possible with swarmplot. Personally I find this kind of plot very difficult to interpret: a good statistical plot should make the patterns in the data immediately apparent, whereas plots with multiple categorical variables that manipulate the size or shape of the points quickly become more like puzzles. My recommendation in these cases (following Andrew Gelman) is to make more than one plot, each with relatively simple semantics.

You don't have to agree, of course, but you will have to make it yourself using matplotlib.

mwaskom
  • 46,693
  • 16
  • 125
  • 127
  • 1
    Thanks for your comment. I definitely agree with you in terms of presenting the data to others. However, this is for me to explore the data from an experiment I designed, implemented, and ran and also developed models to simulate before hand. A plot like this would be allow me to see the progression of participants across time (e.g., if overtime the blue triangles get bigger, it means that participants have found the optimal peers to copy in their group). I guess the only way to make it is with matplotlib, as you have suggested. – amaatouq Mar 10 '17 at 14:12
  • An immediate application would be to create a print-friendly/colorblind-friendly swarmplot where hue also applies to markershape. – ImportanceOfBeingErnest Oct 18 '18 at 21:23
0

I am facing the same issue, and actually the solution seems to be pretty simple at least for the marker type!

Just divide your dataframe in subdataframes, each for a different marker type. The you make a swarmplot on top of each other, and that's it.

If the size of the dot, is also a categorical variable, you just need to do the same as above where each subdtaframe will represent a marker and a different size.

If size is continuous, then it seems you would need to plot each dot independently in a for loop, but for that I would use matplotlib.pyplot.

alejandro
  • 521
  • 8
  • 18