Change inter quartile range(IQR) for boxchart

15 ビュー (過去 30 日間)
Bhaskar R
Bhaskar R 2021 年 12 月 6 日
回答済み: Jaynik 2024 年 4 月 2 日
Hi,
I had to use only boxchart for my application where I need to change Inter Quartile Range(IQR) from default range i.e 25% for the lower and 75% is the upper quartiles respectly. I see changing of IQR in boxplot using the Outliers Tag box object possible, but for the boxchart there is no much help found in different forums.
As from the help of boxchart, it is using quantile Algorithms where the upper quartile corresponds to the 0.75 quantile and the lower quartile corresponds to the 0.25 quantile defauly, I have statisticas and machine learning toolbox,
Can I get any help?

回答 (1 件)

Jaynik
Jaynik 2024 年 4 月 2 日
Hi Bhaskar,
From the given description, it seems like you want to add whiskers to a custom value of IQR instead of the default. As per my understanding, this is not directly possible with the 'boxchart' function. Here is a possible workaround that adds the custom whiskers to the initial plot:
% Assuming that data stores your data
bc = boxchart(data);
% Adding custom whiskers:
lowerPercentile = 0.3; % 30th percentile
upperPercentile = 0.7; % 70th percentile
% Calculate custom percentiles
customBounds = quantile(data, [lowerPercentile, upperPercentile]);
ax = gca;
hold on;
xPos = 1;
yLower = customBounds(1);
yUpper = customBounds(2);
% Plot lines for custom percentiles
% Adjust x-coordinates based on your data structure and boxchart layout
plot(ax, [xPos-0.4, xPos+0.4], [yLower, yLower], '--r');
plot(ax, [xPos-0.4, xPos+0.4], [yUpper, yUpper], '--r');
hold off;
This script calculates and plots lines representing custom whiskers at the 30th and 70th percentiles. It is important to note that this approach visually marks the custom whiskers without altering the box itself.
Hope this helps!

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by