MATLAB: How to compare two columns at the bar chart

bar chart

I would like add this dotted line to the bar chart (MATLAB 2016a)

Best Answer

Here's a demo to get you started.
clf()
h = bar([210, 140, 175, 160]);
set(gca,'xtick',1:4,'xticklabel',{'A','B','C','D'})
hold on
% Get height of each bar
y = h.YData;
% draw horizontal line between B and D with a height
% equal to the tallest bar between them.
xLine = [2,4]; % draw line between bars centered at 2 and 4
halfWidth = 0.4; %estimate of 1/2 the width of the bars
maxHeight = max(y(xLine(1):xLine(2)));
plot(xLine + halfWidth*[-1,1], maxHeight * [1,1], ':','LineWidth',3, 'color', [1 0.64 0]) %orange
% draw horizontal line between A and D...
xLine = [1,4]; % draw line between bars centered at 1 and 4
maxHeight = max(y(xLine(1):xLine(2)));
plot(xLine + halfWidth*[-1,1], maxHeight * [1,1], 'g:','LineWidth',3)
% Draw vertical line at bar B, right edge
xLine = 2; % index of bar where vertical line will be drawn along right edge
plot(xLine+halfWidth * [1,1], [y(xLine), max(y)], 'r:','LineWidth',3)
190819 171411-Figure 1.jpg