%% Art4_v7_Fig4.m

clear all
close all
clc

% Roeland C. van de Vijsel
% NIOZ Yerseke, The Netherlands
% www.nioz.nl
% V1 - 23 July 2020

% This Matlab script creates the boxplot for Figure 4 in the PhD Thesis of 
% Roeland C. van de Vijsel (https://doi.org/10.33612/diss.160081233).

%% Load seedling density data
VAR = 'SeedDens';
summary = csvread(['output/',VAR,'_summary.csv'],1,2);

AlgalLevee_mea = summary(1,2);
AlgalRidge_mea = summary(2,2);
BareLevee_mea = summary(3,2);
BareMud_mea = summary(4,2);

AlgalLevee_sem = summary(1,4);
AlgalRidge_sem = summary(2,4);
BareLevee_sem = summary(3,4);
BareMud_sem = summary(4,4);

%% Prepare data for barplot
X1 = [0.5 1.5 2.5 3.5];
Y1 = [BareMud_mea, BareLevee_mea, AlgalLevee_mea, AlgalRidge_mea];
Z1 = [BareMud_sem, BareLevee_sem, AlgalLevee_sem, AlgalRidge_sem];

%% Plot Seedling density (Fig4)
lw = 2; % LineWidth
fs = 17; % FontSize

close(figure(1));figure(1)

bar(X1,Y1,'FaceColor',[0.5 0.5 0.5],'EdgeColor',[0 0 0]); hold on
% bar(X1(2),Y1(2),'FaceColor',[0.8 0.8 0.8],'EdgeColor',[0 0 0]);
errorbar(X1,Y1,Z1,'.k','LineWidth',lw)

set(gca,'xtick',X1,'xticklabel',{'Mud/no algae','Levee/no algae','Levee/algae', 'Ridge/algae'},'FontSize',fs-2)
axis([0 4 0 400])
ylabel('Average seedling density [m^{-2}]','FontSize',fs)
xlabel('Substrate type','FontSize',fs)
title('Plant seedling density', 'Units', 'normalized', 'Position', [0.28, 0.9, 0],'FontSize',fs+5)

saveas(gcf,'Art4_v7_Fig4_SeedDens.pdf')
