%% Add Two Legends
% When you display multiple data sets in the same axes, you can include multiple legends. To manage the alignment of the legends, create your chart in a tiled chart layout.
% Create two sets of data, and plot them together in the same axes object within a tiled chart layout.

x = 1:20;
y1 = rand(1,20);
y2 = rand(1,20);
sz1 = randi([20 500],[1,20]);
sz2 = randi([20 500],[1,20]);

% Plot data in a tiled chart layout
t = tiledlayout(1,1);
nexttile
bubblechart(x,y1,sz1)
hold on
bubblechart(x,y2,sz1)
hold off

%
% Add a bubble legend for illustrating the bubble sizes, and add another legend for illustrating the colors. Call the bubblelegend and legend functions with a return argument to store each legend object. Move the legends to the right outer tile of the tiled chart layout by setting the Layout.Tile property on each object to 'east'.

blgd = bubblelegend('Population');
lgd = legend('Springfield','Fairview');
blgd.Layout.Tile = 'east';
lgd.Layout.Tile = 'east';

% Copyright 2020 The MathWorks, Inc.