且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

MATLAB中的Beeswarm箱线图(用于分类数据的散点图)

更新时间:2022-11-23 07:38:59

文件交换上有一个名为 plotSpread 可以进行以下绘制:

plotSpread({rand(100,1),randn(100,1)})

       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'})

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:

Different colors for additional group is very nice feature but it not needed for me now.

There is a function on the file exchange called plotSpread that can do these plots:

plotSpread({rand(100,1),randn(100,1)})

       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'})