Is there a way to plot multiple boxplots in a subplot?
31 views (last 30 days)
Show older comments
Leutrim Mehmeti
on 31 Mar 2023
Edited: Leutrim Mehmeti
on 1 Apr 2023
F(sub,day).Cond(Cond).Targ(TarInd_y,TarInd_x).RT(trcnt(Cond,TarInd_y,TarInd_x))=RT;
figure;
for day=1:1
for Cond=1:3
for sub=1:1
for r=1:rows
for c=1:columns
subplot(rows,columns,(r-1)*columns+c), hold on;
boxplot(F(sub,day).Cond(Cond).Targ(r,c).RT)
xticklabels({'Cond One', 'Cond Two', 'Cond Three'});
end
end
end
end
end
%F(1, 1).Cond(1).Targ(1, 1).RT this would be==>%Subject 1 Day one conditions 1:3,Target row 1 column 1(aka top
%left).Reaction time values
So I have some data from an experiment where I had subjects come in on 3 different days for a hand reaching task. In this experiment we had right, left and choice (subject chooses between r and l hand to reach to a target) trials.
I am trying to plot the reaction time values (a vector of 10 values for cond=1 or 2, 20 for cond=3) for all 33 targets (3 rows of 11 columns) for one subject for each different condition (3) as it's own boxplot in a subplot. The code above plots the boxplots on top of one another.
The question is very simple: is there a way to plot cond=1 trials/RT values as the first x-axis tick boxplot and cond2 and cond 3 as second and third tick on the x-axis.
Thanks!
0 Comments
Accepted Answer
Cris LaPierre
on 31 Mar 2023
Sure. Turn your condition (0, 1, 3) into a categorical array, and use that to group your data using boxchart.
% tiledlayout(3,11)
C1 = rand(10,1)*10;
cond1 = categorical(zeros(size(C1)));
C2 = rand(10,1)*10;
cond2 = categorical(ones(size(C2)));
C3 = rand(20,1)*10;
cond3 = categorical(ones(size(C3))*3);
C = [C1; C2; C3];
cond = [cond1; cond2; cond3];
boxchart(cond,C)
5 Comments
Cris LaPierre
on 31 Mar 2023
In this situation, I don't think your condition loop is gaining you anything. Just hard code it. Here's one approach. Note that due to the number of graphs, you will want to make the figure fullscreen.
Since boxplots are a visual way to quickly compare different datasets, I might also suggest fixing the ylims of all boxcharts so that you can easily compare them.
tiledlayout(rows,columns)
for day=1:1
for sub=1:1
for r=1:rows
for c=1:columns
C1 = F(sub,day).Cond(1).Targ(r,c).RT;
cond1 = categorical(zeros(size(C1)));
C2 = F(sub,day).Cond(2).Targ(r,c).RT;
cond2 = categorical(ones(size(C2)));
C3 = F(sub,day).Cond(3).Targ(r,c).RT;
cond3 = categorical(ones(size(C3))*3);
C = [C1, C2, C3];
cond = [cond1, cond2, cond3];
nexttile
boxchart(cond,C)
ylim([0,0.6])
end
end
end
end
More Answers (0)
See Also
Categories
Find more on Axis Labels in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!