%% Compare Two Pie Charts
% Create vectors y2010 and y2011, that contain financial data for two years. Then create a cell array containing the labels for the values.

y2010 = [50 0 100 95];
y2011 = [65 22 97 120];
labels = {'Investments','Cash','Operations','Sales'};

%
% Create a 1-by-2 tiled chart layout, and display two pie charts that each have a title. Then display a shared legend in the east tile of the layout. To do this, call the legend function with a return argument to store the legend object. Then move the legend to the east tile by setting the Layout.Tile property to 'east'.

t = tiledlayout(1,2,'TileSpacing','compact');

% Create pie charts
ax1 = nexttile;
pie(ax1,y2010)
title('2010')

ax2 = nexttile;
pie(ax2,y2011)
title('2011')

% Create legend
lgd = legend(labels);
lgd.Layout.Tile = 'east';

% Copyright 2020 The MathWorks, Inc.