# how do you make a scatter plot with categorical data with connecting lines?

25 views (last 30 days)
nines on 9 Nov 2021
Answered: Star Strider on 9 Nov 2021
Hello!
I have two 5x34 matrices that I want to compare in a plot like as follows;
My code so far is as follows:
%% dot plot
for i = 1:length(subjects)
subj=subjects{i} % individual subject
figure(1)
x = ones(1, length(lh_mean_nocap))
scatter(x, lh_mean_nocap, 'b', 'filled'); hold on
scatter(x, rh_mean_nocap, 'b', 'filled')
set(gcf, 'color', 'w');
hold on;
x = 2 * ones(1, length(lh_mean_nocap));
scatter(x, lh_mean_cap, [], [0.9100 0.4100 .1700], 'filled'); hold on
scatter(x, rh_mean_cap, [], [0.9100 0.4100 .1700], 'filled'); hold on
title('Grey White Matter Mean Signal Ratio - All Subjects');
ax = gca;
ax.XTick = [1,2];
ax.XTickLabels = {'No Cap', 'R-Net'}
ylabel('Grey White Matter Mean Signal')
xlim([0, 3])
end
Which gives me a graph with two categorical parts, however, I want to connect the corresponding categoricalvariables.
thank you!
dpb on 9 Nov 2021
You forgot to attach your data...
You just want a line between the means of each of the sets of scatter points, I guess? Since there's only one point shown on the sketch it's not at all clear what the data sizes are...

Star Strider on 9 Nov 2021
The data being used would help produce an appropriate response.
The ‘connecting lines’ request eliminates scatter as an option because it plots only discrete points without connecting lines.
The plot function connects the markers with lines.
This works in R2021b. Posting the version/release being used for this would allow a more specific reply if this does not work correctly in the version/release being used.
x = categorical({'a','b','c','d'});
y = rand(size(x));
figure
plot(x, y, '-p')
grid
Experiment with the actual data to see if it works correctly using this approach.
.