How to plot an histogram representing the range of motion, a bit like a boxplot ?
5 views (last 30 days)
Show older comments
Hello,
I would like to plot an histogram from my data, that represent the range of motion (ROM), like the following picture.

The idea is to represent the value of the ROM (size of the bar), the min and max of the ROM (location of the bar) and the standard deviation, preferably the std of the minimum down and std of the maximum upwards.
I tried bar function but I didn't find how to determine the bottom of the bar or other parameter to implement the location (on the y axis) of the bar.
I tried boxplot function too, it seems to be good but the parameters do not match what I am looking for (25 and 75 percentil instead of min and max, median instead of mean, min and max instead of standard deviation).

Does anyone has an idea to do this ?
0 Comments
Answers (1)
Pratyush Swain
on 3 Oct 2023
Hi Thomas,
I understand you want to represent range of motion(ROM) as size of bar,the minimum and maximum of the ROM as the location of the bar, and also visualize the standard deviation.You can leverage a combination of 'bar','errorbar' and 'line' function to acheive this task. Please refer to the example code below:
% Example range of motion data for three groups
group1_rom = [10, 15, 12, 8, 20, 17, 22];
group2_rom = [5, 7, 9, 6, 12, 10, 8, 15];
group3_rom = [18, 16, 20, 22, 19, 23];
% Calculate statistics for each group
group1_mean = mean(group1_rom);
group1_min = min(group1_rom);
group1_max = max(group1_rom);
group1_std = std(group1_rom);
group2_mean = mean(group2_rom);
group2_min = min(group2_rom);
group2_max = max(group2_rom);
group2_std = std(group2_rom);
group3_mean = mean(group3_rom);
group3_min = min(group3_rom);
group3_max = max(group3_rom);
group3_std = std(group3_rom);
% Create a bar plot with error bars
figure;
bar([group1_mean, group2_mean, group3_mean]);
hold on;
% Error Bar to represent std dev
errorbar([1, 2, 3], [group1_mean, group2_mean, group3_mean], ...
[group1_std, group2_std, group3_std], 'k.', 'LineWidth', 1);
% Set the x-axis labels
xticks([1, 2, 3]);
xticklabels({'Group 1', 'Group 2', 'Group 3'});
% Set the y-axis label
ylabel('Range of Motion');
% Set the plot title
title('Range of Motion Representation');
% Add vertical lines for the minimum and maximum
line([0.85, 1.15], [group1_min, group1_min], 'Color', 'r', 'LineWidth', 2);
line([1.85, 2.15], [group2_min, group2_min], 'Color', 'r', 'LineWidth', 2);
line([2.85, 3.15], [group3_min, group3_min], 'Color', 'r', 'LineWidth', 2);
line([0.85, 1.15], [group1_max, group1_max], 'Color', 'r', 'LineWidth', 2);
line([1.85, 2.15], [group2_max, group2_max], 'Color', 'r', 'LineWidth', 2);
line([2.85, 3.15], [group3_max, group3_max], 'Color', 'r', 'LineWidth', 2);
% Add legend
legend('Mean', 'Standard Deviation', 'Min/Max');
hold off;
% Add vertical lines for the minimum and maximum
line([0.85, 1.15], [group1_min, group1_min], 'Color', 'r', 'LineWidth', 2);
line([1.85, 2.15], [group2_min, group2_min], 'Color', 'r', 'LineWidth', 2);
line([2.85, 3.15], [group3_min, group3_min], 'Color', 'r', 'LineWidth', 2);
line([0.85, 1.15], [group1_max, group1_max], 'Color', 'r', 'LineWidth', 2);
line([1.85, 2.15], [group2_max, group2_max], 'Color', 'r', 'LineWidth', 2);
line([2.85, 3.15], [group3_max, group3_max], 'Color', 'r', 'LineWidth', 2);
% Add legend
legend('Mean', 'Standard Deviation', 'Min/Max');
hold off;
In this example, we have three groups (group1_rom, group2_rom, and group3_rom) representing the range of motion data. We calculate the mean, minimum, maximum, and standard deviation for each group. Then, we create a bar plot with the mean values and add error bars using the errorbar function, which represent the standard deviation. Additionally, vertical lines are added to indicate the minimum and maximum values
Hope this helps.
0 Comments
See Also
Categories
Find more on Data Distribution Plots 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!