Is there a way to plot multiple boxplots in a subplot?
6 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Cris LaPierre
2023-3-31
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 个评论
Cris LaPierre
2023-3-31
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

更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Axis Labels 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
