Boxplot overlay - multiple variables

Hi,
I am trying to boxplot quite a few variables on the same plot with no luck so far.
I have skin response data (numerical). I have two 'chooser' categories (characters/letters SS or ES): Self-selected(SS) VS Experimenter-selected(ES) songs. Within the 'chooser categories, I have two other variants (also characters): Arousing VS relaxing song.
The idea is to have boxplots of 'chooser' side by side showing the below:
SS Arousing + ES Arousing boxplots side by side & SS Relaxing + ES Relaxing boxplots side by side
Example similar to the boxplot I am trying to get with the above variables is attached.
I have tried a few alternatives (like holding on, creating aa grouping variable, etc) that I found on answers from the forum but my plot always comes up blank and I have had a different error with each method I tried so far.
Any ideas on how to produce such a plot would be greatly appreciated please. Thanks so much in advance.

Respuestas (1)

Shivam
Shivam el 5 de Nov. de 2024
Hi Rita,
Here is one example implementation which leverages the boxplot function to achieve the desired layout using skin response data:
skinResponse = randn(100, 1); % Replace with your actual skin response data
% Grouping variables
chooserCategory = [repmat({'SS'}, 50, 1); repmat({'ES'}, 50, 1)];
songType = [repmat({'Arousing'}, 25, 1); repmat({'Relaxing'}, 25, 1); ...
repmat({'Arousing'}, 25, 1); repmat({'Relaxing'}, 25, 1)];
% Combine grouping variables
group = strcat(chooserCategory, '-', songType);
figure;
boxplot(skinResponse, group, 'Labels', {'SS-Arousing', 'SS-Relaxing', 'ES-Arousing', 'ES-Relaxing'});
xlabel('Category');
ylabel('Skin Response');
Hope it helps.

3 comentarios

Hi,
Thanks for your help in advance. It isn't unfortunately doing what I need. Maybe I didn't explain myself clearly enough.
I have tried a few more things.
boxplot(data1.GSR,data1.g2,'colorgroup',data1.g1)
ylabel('Dependent variable: GSR')
legend
On the above (that still doesn't work), data1.GSR is a column of numerical values. data1.g2 is a column of the same size of the other but populated with A or R (stands for Arousing or Relaxing). Finally, data1.g1 is also a column, that is populated with ES or SS (that stand for Experimenter-selected or Self-selected).
Screenshot of the table where I am reading my data from for reference:
Something like this would do it. (A and R on the top left are meantt to be the legend of the boxplot) :)
Rita Campos
Rita Campos el 5 de Nov. de 2024
Update: I've done it! :) Thanks anyway!
Voss
Voss el 5 de Nov. de 2024
@Rita Campos Please post the code that worked for you, so that others may benefit from it.

Iniciar sesión para comentar.

Etiquetas

Preguntada:

el 5 de Nov. de 2024

Comentada:

el 5 de Nov. de 2024

Community Treasure Hunt

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

Start Hunting!

Translated by