2
votes

How would you produce in Matlab a categorical scatter plot comparable to this?

Categorical scatter plot in R

The above chart was generated in R, in response to this question.

2
I'd use subplot... those are really three separate plots. Alternatively, you could scale each data sets "x"-values to fit a defined range (I'd choose 1) and then just add a constant to each - Dan

2 Answers

3
votes

You can use the undocumented jitter property of scatter:

% create example data
ydata = rand(50, 3)*2+2; 

[r, c] = size(ydata);

xdata = repmat(1:c, r, 1);

% for explanation see 
% http://undocumentedmatlab.com/blog/undocumented-scatter-plot-jitter
scatter(xdata(:), ydata(:), 'r.', 'jitter','on', 'jitterAmount', 0.05);

hold on;

plot([xdata(1,:)-0.15; xdata(1,:) + 0.15], repmat(mean(ydata, 1), 2, 1), 'k-')

ylim([0 max(ydata(:)+1)])

This results in:

Example figure

2
votes

I know this post is old, but I recently updated this function, that you may find useful, since it distributes the points the same way always and allows for very high personalization of the shape, colors and distributions of the points. I think it reproduces quite well the shape of those graphs showed in some publications. Have a look if you are interested

http://www.mathworks.com/matlabcentral/fileexchange/54243-univarscatter

Image of the plots