%% Specify Axes for Box Charts
% Display a side-by-side pair of box charts using the tiledlayout and nexttile functions.
% Load the patients data set. Convert Smoker to a categorical variable with the descriptive category names Smoker and Nonsmoker rather than 1 and 0.

load patients
Smoker = categorical(Smoker,logical([1 0]),{'Smoker','Nonsmoker'});

% Create a 1-by-2 tiled chart layout using the tiledlayout function. Create the first set of axes ax1 within it by calling the nexttile function. In the first set of axes, display two box charts of systolic blood pressure values, one for smokers and the other for nonsmokers. Create the second set of axes ax2 within the tiled chart layout by calling the nexttile function. In the second set of axes, do the same for diastolic blood pressure.

tiledlayout(1,2)

% Left axes
ax1 = nexttile;
boxchart(ax1,Systolic,'GroupByColor',Smoker)
ylabel(ax1,'Systolic Blood Pressure')
legend

% Right axes
ax2 = nexttile;
boxchart(ax2,Diastolic,'GroupByColor',Smoker)
ylabel(ax2,'Diastolic Blood Pressure')
legend

% Copyright 2019 The MathWorks, Inc.