How do I create a beeswarm plot and boxplot together?

7 vues (au cours des 30 derniers jours)
fz
fz le 28 Juil 2022
Modifié(e) : dpb le 28 Juil 2022
I need to create a plot similar to the figure below

Réponses (1)

dpb
dpb le 28 Juil 2022
Modifié(e) : dpb le 28 Juil 2022
The basic starting point isn't difficult; some tedium in setting all the conditional fixups of symbols, colors, etc, etc., ... but start with
hBXP=boxplot(x);
hold on
ylim([1/100 100])
hAx=gca;
hAx.YScale='log';
hL=plot(x,'.');
This will put the data on top of the boxplot and return an array hL of line handles, one for each column in x-- you'll have to set each line handle line color, marker, etc., to suit. This can be done with predefined constants as cell arrays for some ease in coding.
The nicety the above doesn't handle is adding "jitter" to the x-axis positions of the data -- I presume that is simply randomized in the given figure, there aren't actual varying data values are there?
I recall a Q? on forum about doing so in the not too distant past, but I can't think of a specific way to find it at the moment...

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by