I am looking for a function to create a so called Beeswarm boxplot. This is very popular plots used in medicine and biology and I was surprised not to find it for MATLAB.
Basically the numerical data for each group are splitted to bins and jitter of points depends on number of points in a particular bin.
Here is an example done with R using BEESWARM function:
beeswarm example
Different colors for additional group is very nice feature but it not needed for me now.
1 Answer 1
There is a function on the file exchange called plotSpread that can do these plots:
plotSpread({rand(100,1),randn(100,1)})
enter image description here
data = [randn(50,1);randn(50,1)+3.5]*[1 1];
catIdx = [ones(50,1);zeros(50,1);randi([0,1],[100,1])];
plotSpread(data,'categoryIdx',catIdx,...
'categoryMarkers',{'o','+'},'categoryColors',{'r','b'})
enter image description here
-
Thanks a lot, @Jonas. I'm using distributionPlot a lot, but somehow missed this function existence. It's perfectly fit my current needs. Consider including a spread plot as an example on FE. Also it would be nice if the function could return handles for mean-median.yuk– yuk2012年03月20日 15:31:34 +00:00Commented Mar 20, 2012 at 15:31
-
@yuk: I had debated as to whether I should put it as a separate entry on FE; but maybe it would make sense. There's a bunch of features I've added for
distributionPlot
that I could copy over toplotSpread
, and I'd rather do one big overhaul than many small ones, so what other features would you like inplotSpread
?Jonas– Jonas2012年03月20日 16:39:31 +00:00Commented Mar 20, 2012 at 16:39 -
I think it could be a great separate submission on FE. And once you ask for other features here are some: (1) output like in distributionPlot, (2) grouping (boxplot like), (3) color groups, (4) hor/vert orientation, (5) input arguments as name/value pairs, (6) if possible different methods as in R/beeswarm.yuk– yuk2012年03月20日 18:23:31 +00:00Commented Mar 20, 2012 at 18:23
-
@yuk: An independent version of plotSpread has been uploaded. It contains features 1,2,3,4,5, and 6-ish, though I use slightly different methods.Jonas– Jonas2012年06月11日 20:07:42 +00:00Commented Jun 11, 2012 at 20:07
-
Thank you, @Jonas. Sorry, I was not able to test it as promised. In rush at work.yuk– yuk2012年06月12日 03:20:06 +00:00Commented Jun 12, 2012 at 3:20