tiled layout with boxplot overlaid by scatterplot

4 views (last 30 days)
I have a boxplot with an overlaid scatterplot, that I would now like to put into a tiled layout. The data (PSD) is grouped by condition (on the x axis for boxchart) and by the participant number (colors of the scatter plot). When I change the column of PSD, I would like it to plot it in another tile. However, when I try to put it in the tiled layout, the box chart no longer shows up. In the code I've commented out how I tried to implement the tiledlayout.
%tiledlayout('flow');
clear color
%preallocate an array of of colors with NaN
color=NaN(length(double(type)), 3);
for i=1:npeople
[colorinx,tf]=listdlg('PromptString', append('Select the files for participant ', num2str(i)), 'SelectionMode','multiple','ListString',rownames, 'ListSize', [300 200]);
%list of possible colors
colors={'red'; 'green'; 'blue'; 'magenta'; 'yellow'; 'black'};
%assign the colors a color code
colorCodes = [[1 0 0]; [0 1 0]; [0 0 1]; [0 1 1]; [1 0 1]; [1 1 0]; [0 0 0]];
coloroption=listdlg('PromptString', 'Select color for this participant', 'SelectionMode','multiple','ListString',colors, 'ListSize', [300 200]);
%match the colors selected with their color code
color(colorinx,:)=colorCodes(coloroption,:).*ones(size( color(colorinx,:)));
end
%for loop that changes PSD values being plotted
for i=1:5
%make the grouping column (cond) numerical so that it can be used in scatterplot
type = renamecats(categorical(cond), {'condition x', 'condition y'}, {'1','2'});
%make a boxplot based on the conditions and all of the points
%nexttile
figure()
hold on
boxchart(type, PSD(points,i));
ylabel('PSD (%)')
xlabel('Condition')
%overlay the scatterplot onto the boxplot made earlier
scatter(double(type), PSD(points,i), 25, color, 'filled', 'XJitter', 'rand', 'XJitterWidth', 0.3)
end
Currently I can get my overlaid boxchart like this (only one color shown because this is data for one person):
But I would like it to look like this in the tile layout:
What I am missing? Thanks!

Answers (1)

alexander Mcghee
alexander Mcghee on 27 Apr 2023
The problem is that the boxchart function doesn't work well within a tiled layout. However, you can use the boxplot function instead, which works fine within a tiled layout.
tiledlayout('flow');
clear color
%preallocate an array of colors with NaN
color = NaN(length(double(type)), 3);
for i = 1:npeople
[colorinx,tf] = listdlg('PromptString', append('Select the files for participant ', num2str(i)), 'SelectionMode','multiple','ListString',rownames, 'ListSize', [300 200]);
%list of possible colors
colors = {'red'; 'green'; 'blue'; 'magenta'; 'yellow'; 'black'};
%assign the colors a color code
colorCodes = [[1 0 0]; [0 1 0]; [0 0 1]; [0 1 1]; [1 0 1]; [1 1 0]; [0 0 0]];
coloroption = listdlg('PromptString', 'Select color for this participant', 'SelectionMode','multiple','ListString',colors, 'ListSize', [300 200]);
%match the colors selected with their color code
color(colorinx,:) = colorCodes(coloroption,:).*ones(size(color(colorinx,:)));
end
%for loop that changes PSD values being plotted
for i = 1:5
%make the grouping column (cond) numerical so that it can be used in scatterplot
type = renamecats(categorical(cond), {'condition x', 'condition y'}, {'1','2'});
%make a boxplot based on the conditions and all of the points
nexttile
hold on
boxplot(PSD(points,i), type, 'Colors', 'k', 'Symbol', '');
ylabel('PSD (%)')
xlabel('Condition')
%overlay the scatterplot onto the boxplot made earlier
scatter(double(type), PSD(points,i), 25, color, 'filled', 'XJitter', 'rand', 'XJitterWidth', 0.3)
end

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!