Scatter plot with mean for multiple groups
Ältere Kommentare anzeigen
Hello,
I'm trying to create a scatter plot looks like this:

I don't know the original name but I found this link : https://www.mathworks.com/matlabcentral/fileexchange/62871-cigarscatterplot?s_tid=srchtitle_scatter%20plot_15 I also attached the code that I used. It's slightly different than the original one (because I have more groups).
This is the part of data. I have 4 ranges and 3 experiments for each drug group. for every range I'm trying to add all 3 experiment for each group in same vertical area and box. eventually, my aim is to create 4 boxes for each range next to each other . (I mean; box = the area whic is seperated with dashlines in the scatterplot) and each box is needed to have 4 groups.

I wrote this command
Control= [0,0,0]
ap= [5, 36, 52]
Drug1 = [1,1,1]
bp = [32, 16, 0]
Drug2 = [2,2,2]
cp = [0, 15, 5]
Drug3 = [3,3,3]
dp= [16, 0.00, 1]
x = [Control, Drug1, Drug2, Drug3]
y= [ap, bp, cp, dp]
[x,y]= Tugce3CigarScatterPlot(x,y)
I could only add 1 range for 4 groups with all 3 experiment and looked like this. 0 is Control, 1 is Drug 1,.... , and ylim is experiment data.

I need to change 0 with Control, 1 with Drug 1,... n the xlim. Also need to add different ranges next to this plot.
I'm not sure if it's multiple questions in one question but I couldn't find any information to create this kind of plot other than the link above. If anyone knows this scatterplot's original name, maybe I can search for it and find more information, otherwise I would be really apreaciated for any suggestions for any steps.
Thank you so much
2 Kommentare
dpb
am 24 Sep. 2022
I can't follow the explanation of what you think the appearance should be in the end, sorry...draw a sketch by hand of what you think the result should look like for a given group/experiment to illustrate. As is, the what-you-want and what-you-got-so-far are so intertwined it's just not easy to separate...
Then, if you expect somebody to try to do something specifically towards that end, attach the data for something to work with...
Tugce Irem
am 26 Sep. 2022
Akzeptierte Antwort
Weitere Antworten (1)
x = readtable("https://www.mathworks.com/matlabcentral/answers/uploaded_files/1136975/MATLAB_exampledata.xlsx");
x.Group = categorical(x.Group);
x.Range = categorical(x.Range)
urange = unique(x.Range);
n = length(urange);
for i=1:n
subplot(1,n,i)
x1 = x(x.Range==urange(i), :);
scatter(x1, 'Group', {'percentage', 'percentage_1', 'percentage_2'});
hold on
plot((double(x1.Group)+[-.5 .5])', (mean(x1{:, 3:5}, 2)+[0 0])', 'r-')
title(urange(i))
end
4 Kommentare
Tugce Irem
am 27 Sep. 2022
dpb
am 27 Sep. 2022
@Chunru -- where did you find the facility in scatter to use grouping variables? I can find no reference to that in R2022b doc's -- I had forgotten about gscatter in the Statistics TB and just discovered above by accident that base scatter has been upgraded from vector x,y only to accepting a matrix (I'm still on R2020b on base machine; these came R2021 or later).
It's also a revelation about the addition of the line to what look to be categorical axes -- unless they're not in using the new version; I'll have to poke around some at the innards of the axes object...
Steven Lord
am 27 Sep. 2022
In this case 'Group' is not a name-value argument, it's the name of a variable in the table. If you look at the documentation page for the scatter function this is using the scatter(tbl, xvar, yvar) syntax. See the "Plot Data from a Table" example on that page. This functionality was introduced in release R2021b.
dpb
am 28 Sep. 2022
@Steven Lord -- (Headslap!) Yeah, thanks! I got myself confused and then couldn't get the wrong idea out of head. Too used to scatter not being vectorized to take an array, I guess.
Kategorien
Mehr zu Scatter Plots finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

