Displaying error bars on scatter plot (Bland-Altman plot)
4 ビュー (過去 30 日間)
古いコメントを表示
Hello all,
I have a scatter plot (Bland-Altman plot) showing the agreement between two sensors measuring knee angle for 1 gait cycle. I would like to plot the error bars in the y direction but I am having issues with this.
I want the initial HS one colour and then the final index which is HS another colour. I have plotted the mean and +-2SD to indicate the spread of the data.
I have then tried to plot the error bars which have not worked, please would you be able to advise how to do this.
Please see code below:
%% Average Bland-Altman plot
% Plot mean difference line
figure;
first_index = 1;
last_index = numel(mean_data);
scatter(mean_data(first_index), diff_data(first_index), 'filled', 'MarkerFaceColor', 'green');
hold on
scatter(mean_data(last_index), diff_data(last_index), 'filled', 'MarkerFaceColor', 'red');
hold on
scatter(mean_data(2:100), diff_data(2:100), 'filled','MarkerFaceColor', 'black');
hold on;
%+- 2SD
plot([-10 70], [mean_diff + 2*std_diff, mean_diff + 2*std_diff], 'r--');
plot([-10 70], [mean_diff - 2*std_diff, mean_diff - 2*std_diff], 'r--');
%mean diff line
plot([-10 70], [mean_diff, mean_diff], 'k-', 'LineWidth', 1);
%calculate error bars
error_bar_y = errorbar(mean_data,diff_data, 'vertical', 'LineStyle', 'none');
set(error_bar_y, 'color', 'k', 'LineWidth', 2)
legend({'HS_1', 'HS_2', 'Average gait cycle Data', '+ 2 SD', '- 2 SD', 'Mean Difference'});
hold on
xlim([-10 70])
ylim([-10 10])
xlabel('Mean($\o - \bar{\o}$) (deg)', 'Interpreter','Latex')
ylabel('Difference (deg)')
0 件のコメント
採用された回答
Star Strider
2024 年 4 月 3 日
We are missing ‘mean_diff’ and ‘std_diff’ . Using rand to correct for that for now.
The errorbar plot needs 2 to 4 arguments, those being the ‘x’ (and optionally ‘y’ coordinates of the data), and the values for the error bars themselves (or the upper and lower errors if they are different). You have supplied only the ‘x’ and ‘y’ coordinates. I do not see any specific error s to plot. Supplying a vector for the errors solves that, although it would be better to have the correct data.
Try this —
matfiles = dir('*.mat');
for k = 1:numel(matfiles)
filename = matfiles(k).name
load(filename)
end
% whos
mean_diff = rand*10;
std_diff = rand;
errors = rand(size(mean_data)); % Create 'errors' Vector For 'errorbar'
figure;
first_index = 1;
last_index = numel(mean_data);
scatter(mean_data(first_index), diff_data(first_index), 'filled', 'MarkerFaceColor', 'green');
hold on
scatter(mean_data(last_index), diff_data(last_index), 'filled', 'MarkerFaceColor', 'red');
hold on
scatter(mean_data(2:100), diff_data(2:100), 'filled','MarkerFaceColor', 'black');
hold on;
%+- 2SD
plot([-10 70], [(mean_diff + 2*std_diff), (mean_diff + 2*std_diff)], 'r--');
plot([-10 70], [mean_diff - 2*std_diff, mean_diff - 2*std_diff], 'r--');
%mean diff line
plot([-10 70], [mean_diff, mean_diff], 'k-', 'LineWidth', 1);
%calculate error bars
error_bar_y = errorbar(mean_data,diff_data,errors, 'vertical', 'LineStyle', 'none');
set(error_bar_y, 'color', 'k', 'LineWidth', 2)
legend({'HS_1', 'HS_2', 'Average gait cycle Data', '+ 2 SD', '- 2 SD', 'Mean Difference'});
hold on
xlim([-10 70])
ylim([-10 10])
xlabel('Mean($\o - \bar{\o}$) (deg)', 'Interpreter','Latex')
ylabel('Difference (deg)')
.
4 件のコメント
Star Strider
2024 年 4 月 3 日
As always, my pleasure!
I noticed that as well when I plotted it. The error bars appear to be symmetric with respect to their centres (the averages), so I believe they are correct. (I do not know how they were calculated.)
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Bar Plots についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!