%% Grain vs. Clumps lofting statistics
% Created by Charles T Pett
% Date created: 2022-09-02

% Produces Figure 2(c)

% Compares number of grains lofted vs. clumps lofted for each run from
% Runs 1-6

clear; clc; close all

% Lofted objects observed in videos from Runs 1-6
% 'g' = grains, 'c' = clumps
g1 = 11; c1 = 6;
g2 = 17; c2 = 3;
g3 = 4; c3 = 1;
g4 = 95; c4 = 28;
g5 = 97; c5 = 10;
g6 = 48; c6 = 4;

% Put into array for histogram
grains = [g1; g2; g3; g4; g5; g6];
clumps = [c1; c2; c3; c4; c5; c6];
gram = [grains clumps];

% Percent of lofted events that are clumps
perc_clump = clumps./(clumps + grains) * 100;

% Plot stats
x = categorical({'Run 1' 'Run 2' 'Run 3' 'Run 4' 'Run 5' 'Run 6'});
b = bar(x,gram);
ylabel('Number of lofting events')
% End point tips for grains
xtips1 = b(1).XEndPoints;
ytips1 = b(1).YEndPoints;
labels1 = string(b(1).YData);
text(xtips1,ytips1,labels1,'HorizontalAlignment','center',...
    'VerticalAlignment','bottom')
% End point tips for clumps
xtips2 = b(2).XEndPoints;
ytips2 = b(2).YEndPoints;
labels2 = string(b(2).YData);
p1 = [' ('; ' ('; ' ('; ' ('; ' ('; ' ('];
p2 = ['%)'; '%)'; '%)'; '%)'; '%)'; '%)'];
labels3 = strcat(p1,num2str(round(perc_clump)),p2);
text(xtips2,ytips2,labels2,'HorizontalAlignment','right',...
    'VerticalAlignment','bottom')
text(xtips2,ytips2,labels3,'HorizontalAlignment','left',...
    'VerticalAlignment','bottom')
legend('Grains','Clumps')
set(gca,'FontSize',18)
