swarmchart
Draws a scatter plot whose points are spread sideways to avoid overlap.
Category: Graphics > 2-D and 3-D Plots
Syntax
swarmchart(x, y)
Draws points at (x, y), spread along x according to the density of the data.
swarmchart(x, y, sz)
Sets the marker size.
swarmchart(x, y, sz, c)
Sets the marker colors.
h = swarmchart(___)
Also returns the chart object.
Description
Points that share an x value would sit on top of each other in a normal scatter plot. A swarm chart shifts them horizontally in proportion to the local density of the y data, so the width of each group shows the distribution of its values.
Input arguments
x- Group positions, such as repeated values or categories.
y- Values to display.
sz- Marker area, as a scalar or vector.
Output arguments
h- Handle of the chart.
Example
Two groups of random values
rng(1);
x = [ones(1, 20), 2*ones(1, 20)];
y = [randn(1, 20), 2 + randn(1, 20)];
swarmchart(x, y)
In the app, the figure is drawn below the code.