Skip to content
Nabarb edited this page Jul 7, 2022 · 4 revisions

Welcome to the Stradivari wiki!

Stradivari plots a combination of half-violins, and raw datapoints (1d or 2d scatter).
[h,u,med] = STRADIVARI(X,Name,Value) displays the violin plots of X. X is a data matrix with columns corresponding to data points and rows to different cases/conditions that will be depicted in different violins. Each case gets its own violin.

Input/Output

---------------------------- INPUT ----------------------------

X - vector of data to be plotted, required.

--------------------- OPTIONAL ARGUMENTS ----------------------

  • ViolinColor - Color vector for violins. Can either be a single vector (all violins the same color) or a matrix M x 3, where M is the first dimension of X (one color per violin). Default colors are the the ColorBrewer pastel1 palette. If you don't know the ColorBrewer project, go check it out. It's awesome.
  • ViolinAlpha - scalar positive value to increase cloud Alpha. (default = .8)
  • ScatterColor - Color vector for scatter. Can either be a single vector (all scatter the same color) or a matrix M x 3, where M is the first dimension of X (one color per scatter). Default colors are the the ColorBrewer set1 palette.

If only ViolinColor or ScatterColor is provided, it sets the other to the same value and ViolinAlpha to 0.6 in order to increase contrast. To contral all three parameters, please provide them explicitely.

  • BandWidth - BandWidth of smoothing kernel (default = 1)
  • DensityType - choice of density algo ('ks' or 'rash'). Default = 'ks'
  • ScatterOffset - scalar value to increase dot dodge amounts (defalut =0.6)
  • ScatterSize - Matrix the same size as X that defines the size of each marker in the scatterplot
  • ScatterWidth - scalar value that defines the percentual amount of cloud area occupied by the scatter
  • ScatterJitter - Same size as X. Used to encode a second dimension in the scatterplot. As defualt the scatterplot is randomly jittered for visualization clarity.
  • Vertical - 1 or zero. Plot clouds vertically or horizzontally
  • LineWidth - scalar value to set global line width of clouds contour (default = 2)
  • Normalization - 'max' or 'area'. Normalization method. The default is 'area' and it ensures that the total area of the half-violin is unitary. By selecting 'max', all the violins will have the same height. this is sometimes useful for qualitative assessments.
  • Coupled - Matrix. determines which rows of X to couple in a full violin. Row numbers along its first dimension get coupled. See below for examples.
  • GridOn - 1 or zero. Plots small markers on the side corresponding to the median value of each distribution
  • BoxOn - logical to turn box-plots on/off (default = 0)

---------------------------- OUTPUT ----------------------------

  • h - figure handle to change more stuff
  • u - parameter from kernel density estimate
  • med - median value for each distribution

Examples

X = rand(5,20) + [1 0.4 0.2 .6 .9]';
figure;

ax=subplot(2,2,1);
ind = [1 3 nan;...
       2 4 5];
stradivari(ax,X,'Coupled',ind);
title('Example 1')

ax=subplot(2,2,2);
ind = [ 1   4;...
        2 nan;
        nan   5;
        nan   3];
stradivari(ax,X,'Coupled',ind,'ViolinAlpha',.6);
title('Example 2')


ax=subplot(2,2,3);
stradivari(ax,X,'Coupled',ind,'GridOn',1,'ScatterOffset',.15,'ScatterWidth',1);
title('Example 3')

ax=subplot(2,2,4);
ind = [1 3 nan;...
       2 4 5];
stradivari(ax,X,'Coupled',ind,'BoxOn',1,'ScatterOffset',.25,'ScatterWidth',.75);
title('Example 4')

ExampleStr

  • Example 1 shows a simple grouping. You can go crazy with this and group staff as you wish, as shown in example 2.
  • Example 2: The number of columns in the matrix passed to coupled determine how many violin groups there are. The rows tell stradivari which one to group and where to put it: the first violin (i.e. X(ind(1,1),:)) goes on top, the second (i.e. X(ind(2,1),:)) below it, the third (i.e. X(ind(3,1),:)) on top again and so on. To skip one position, just put a nan in its corresponding place as shown in example 2.
  • Example 3 shows the grid. Markers are put at the bottom of the figure corresponding to the median value of each distribution. They are color matched to the scatterplot. Also, it shows how to manipulate the size of the scatterplot with _ScatterOffset _and ScatterWidth. _ScatterOffset _sets the offset of the scatter wrt the bottom line of the violin. It's a number between 0 and 1 and refers to the relative violin width. Same goes for ScatterSize. If their sum is bigger than 1, the scatterplot will exceed the violin.
  • Example 4 shows the boxplot superimposed on vertical violins, and some more scatterplot shinanigans.
Clone this wiki locally