How to cluster data in a boxplot?
Mostrar comentarios más antiguos
I am trying to cluster boxplots with no success.
My data is sorted as follows: columns 1 to 8 are subject properties; columns 9 to end are 4 repeated measures of different variables, each column represents a single measure.
I would like to split the file based on the unique combinations of 2 properties (Gait, direction) and cluster the boxplots based on another property (Group). Therefore I would get 4 repeated measures on the x-Axis, its corresponding value on the y-axis and both groups clustered in the plot.
So far I have achieved to plot separately the unique combination of gait, direction and group. I now want to remove group from the combination and use it as a clustering factor.
Can anyone help with this?? thanks in advance!
Data is attached. My code:
numColumns = size(data, 2); % Total number of columns in the data
% Extract unique gait and direction values
uniqueGaits = unique(data.Gait);
uniqueDirections = unique(data.Direction);
uniqueGroups = unique(data.Group);
% Set the maximum number of open figures
maxOpenFigures = 10;
figureCount = 0; % Counter for the number of open figures
% Create a dedicated folder for saving figures
folderName = 'Figures';
if ~exist(folderName, 'dir')
mkdir(folderName);
end
for i = 1:numel(uniqueGaits)
gait = uniqueGaits{i};
for j = 1:numel(uniqueDirections)
direction = uniqueDirections{j};
for k = 1:numel(uniqueGroups)
group = uniqueGroups{k};
% Filter the data based on the unique combination
filteredData = data(strcmp(data.Gait, gait) & strcmp(data.Direction, direction) & strcmp(data.Group, group), :);
% Iterate over the desired range of column indices
for col = 9:4:numColumns
% Extract columns for the current combination
variableData = table2array(filteredData(:, col:col+3));
% Close figures exceeding the maximum limit
if figureCount >= maxOpenFigures
close all;
figureCount = 0;
end
% Create boxplot for the current combination
figure;
boxplot(variableData);
title(['Boxplot - Gait: ', gait, ', Direction: ', direction, ', Group: ', group]);
xlabel('Variables');
ylabel('Value');
% Retrieve column names
columnNames = filteredData.Properties.VariableNames(col:col+3);
% Set x-axis tick labels as column names
xticklabels(columnNames);
% Save the figure in the dedicated folder
saveas(gcf, fullfile(folderName, ['figure_', num2str(figureCount), '.png']));
figureCount = figureCount + 1;
end
end
end
end
% Close any remaining open figures
close all;
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Graphics Performance en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
