%% Update Color of BoxChart Object
% Create a set of color-coded box charts, returned as a vector of BoxChart objects. Use the vector to change the color of one box chart.
%
% Load the patients data set. Convert Gender and Smoker to categorical variables. Specify the descriptive category names Smoker and Nonsmoker rather than 1 and 0.

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

% Combine the Gender and Smoker variables into one grouping variable cgroupdata. Create box charts showing the distribution of diastolic blood pressure levels for each pairing of gender and smoking status. b is a vector of BoxChart objects, one for each group of data.

cgroupdata = Gender.*Smoker;
b = boxchart(Diastolic,'GroupByColor',cgroupdata)
legend('Location','southeast')

%
% Update the color of the third box chart by using the SeriesIndex property. Updating the SeriesIndex property changes both the box face color and the outlier marker color.

b(3).SeriesIndex = 6;

% Copyright 2020 The MathWorks, Inc.