0
votes

I have a data set similar to the following (except I have >50 different groups) and I want to make a scatter plot with the categories along x-axis. I know how to do this if I sort the data manually but the data set is very large so I'd like to automate this.

xdata is a cell array read from excel:

xdata = ['group1' 'group1' 'group1' 'group1' 'group1' 'group1' 'group2' 'group2' 'group2' 'group3' 'group3' 'group3' 'group3' 'group3']';
ydata = rand(14,1);

scatter(xdata,ydata,'jitter')
1
If xdata is a cell array you should define it as such (i.e., xdata = {'group1' ...})Zep

1 Answers

2
votes

I'll just adapt my answer from your deleted question:

% Your data
xdata = {'group1' 'group1' 'group1' 'group1' 'group1' 'group1' 'group2' 'group2' 'group2' 'group3' 'group3' 'group3' 'group3' 'group3'}';
ydata = rand(14,1);

% Transform categorical to integers
[labels, ~, xdata_idx] = unique(xdata);

% Plot!
scatter(xdata_idx , ydata)

% Add labels
set(gca , 'XTick' , unique(xdata_idx), 'XTickLabels' , labels)