Fix overlapping data points using scatter
26 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi there,
I have this figure where I am presenting two different data sets (pink circles and diamonds versus green circles) broke down by proportion of emotion response. Is there an efficient way - using scatter - that I can plot these two data sets side by side for each emotion, rather than have them overlapping?
Here is an exert of my code:
figure,
for sj_CR = nr_CR_subjects
x = repmat(1:7,[nr_CR_subjects,1])';
y_CR = proportions_CR;
scatter(x(:),y_CR(:),120,'o','MarkerFaceColor','g','MarkerEdgeColor','w', 'MarkerFaceAlpha',.09,'MarkerEdgeAlpha',.09)
hold on
end
for emo = 1:nr_emotions
for sj_SR = 1:nr_SR_subjects
x = repmat(1:7,[nr_SR_subjects,1]);
y_SR = proportions_SR;
loc_trials = z_scores <= -1.96 | z_scores >= 1.96;
if ideator_attempt(sj_SR,:) == 1 && loc_trials(sj_SR,emo) == 1
myshape = 'd';
linewi = 2;
linecolor = 'k';
mysize = 150;
elseif ideator_attempt(sj_SR,:) == 0 && loc_trials(sj_SR,emo) == 1
myshape = 'o';
linewi = 2;
linecolor = 'k';
mysize = 150;
elseif ideator_attempt(sj_SR,:) == 1 && loc_trials(sj_SR,emo) == 0
myshape = 'd';
linewi = 1;
linecolor = 'w';
mysize = 120;
elseif ideator_attempt(sj_SR,:) == 0 && loc_trials(sj_SR,emo) == 0
myshape = 'o';
linewi = 1;
linecolor = 'w';
mysize = 120;
end
if thought_intensity_worst(sj_SR,:) == 4
mysat = 1;
elseif thought_intensity_worst(sj_SR,:) == 3
mysat = .7;
elseif thought_intensity_worst(sj_SR,:) <=2
mysat = .4;
end
scatter(x(sj_SR,emo),y_SR(sj_SR,emo),mysize,myshape,'MarkerFaceColor','m','MarkerEdgeColor',linecolor,'LineWidth',linewi, 'MarkerFaceAlpha',mysat,'MarkerEdgeAlpha',mysat)
hold on
set(gcf, 'Position', get(0, 'Screensize'));
set(gca,'XTick',1:nr_emotions, 'XTickLabel',emotions)
set(gcf, 'Position', get(0, 'Screensize'));
xlabel('Emotions')
ylabel('Proportion of Trials')
whitebg([1 1 1])
tmp = fullfile([pth, '/Group_Comparisons/SR_CR_Emotion.jpg']);
saveas(gca,tmp)
end
end
Thank you in advance!
Shannon
0 Commenti
Risposte (2)
Image Analyst
il 11 Nov 2017
Have two category arrays, like HappyPink and HappyGreen. Plot each with it's respective category.
0 Commenti
Eike Petersen
il 5 Giu 2020
Scatter plots with jitter are a solution to exactly this problem. You can create this yourself by simply adding some random noise to the x coordinates of each datum. There might also be builtin solutions; I'm not sure. See, e.g. this discussion: https://stackoverflow.com/questions/30660340/categorical-scatter-plot-in-matlab
Another nice option might be to use a grouped / split violin plot, see here for a few nice examples (unfortunately that's a python library, but just to illustrate what kind of plots I'm referring to): https://seaborn.pydata.org/generated/seaborn.violinplot.html
There are various file exchange options for creating violin plots in Matlab. I'm not sure about the split version, though. Unfortunately, Matlab is really lagging behind in the dataviz department by quite a bit. :(
0 Commenti
Vedere anche
Categorie
Scopri di più su Scatter Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!