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

15 次查看(过去 30 天)
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!
  1 个评论
dpb
dpb 2021-11-9
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
Star Strider 2021-11-9
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.
.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MRI 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by