Fix overlapping data points using scatter

39 visualizaciones (últimos 30 días)
Shannon McNee
Shannon McNee el 11 de Nov. de 2017
Respondida: Eike Petersen el 5 de Jun. de 2020
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

Respuestas (2)

Image Analyst
Image Analyst el 11 de Nov. de 2017
Have two category arrays, like HappyPink and HappyGreen. Plot each with it's respective category.

Eike Petersen
Eike Petersen el 5 de Jun. de 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. :(

Categorías

Más información sobre Line Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by