Clear Filters
Clear Filters

Change inter quartile range(IQR) for boxchart

15 views (last 30 days)
Bhaskar R
Bhaskar R on 6 Dec 2021
Answered: Jaynik on 2 Apr 2024
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?

Answers (1)

Jaynik
Jaynik on 2 Apr 2024
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!

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!