%% Add Legend and Specify Label Alignment
% Create a vertical dash-dot line with both a label and a display name for a legend.

y = [3187 2693 1771 1826 1958 3222 1645];
barh(y,'DisplayName','Daily Sales')
xl = xline(2328,'-.','Average','DisplayName','Average Sales');

%
% Adjust the vertical and horizontal alignment of the label, then display the legend.

xl.LabelVerticalAlignment = 'middle';
xl.LabelHorizontalAlignment = 'center';
legend('show');

% Copyright 2018 The MathWorks, Inc.