close all
% model written by Allison Shaw (contact for assistance: ashaw@umn.edu)
%   last updated: 10 June 2022

fs1 = 10;  % axes labels
fs3 = 09;  % axis numbering
lw2 = 1; % fig edges
lw1 = 1.5; % fig edges
msize1 = 15; % marker size (closed shapes)
msize2 = 5; % marker size (open shapes)

width = 11;
height = 15;
xpos = 3;
ypos = 2;
sx = 0.14;
sy = 0.09;
w = 0.36;
he = 0.23;
dx = 0.12;
dy = 0.09;

g1 = [0 0 0]; % black
g2 = [0.7 0.7 0.7]; % light grey
g3 = [0.5 0.5 0.5]; % med grey

figure(1); clf
hh = gcf;
set(hh,'PaperUnits','centimeters');
set(hh,'Units','centimeters');
set(gcf,'Position',[xpos ypos width height])


%%
load fig4_beta.mat
ind = [6 16 21];
axes('position',[sx sy+2*dy+2*he w he])
    i=ind(1);plot(nvec,speed_FD2(i,:)-speed_base,'.','color',g1,'LineWidth',lw1,'MarkerSize',msize1)
    hold on
    i=ind(2);plot(nvec,speed_FD2(i,:)-speed_base,'.','color',g3,'LineWidth',lw1,'MarkerSize',msize1)
    i=ind(3);plot(nvec,speed_FD2(i,:)-speed_base,'.','color',g2,'LineWidth',lw1,'MarkerSize',msize1)
    line([0 0],[-0.2 0.2],'color','k','LineWidth',lw2)
    legend(['\beta = ' num2str(betavec(ind(1)))],['\beta = ' num2str(betavec(ind(2)))],['\beta = ' num2str(betavec(ind(3)))],'Location','NorthWest')
    text(-0.10,-0.085,'parasite','HorizontalAlignment','center','FontSize',fs3)
    text( 0.12,-0.085,'mutualist','HorizontalAlignment','center','FontSize',fs3)
    axis([-0.25 0.25 -0.1 0.2])
    set(gca,'XTick',-0.2:0.1:0.2)
    set(gca,'FontSize',fs3,'LineWidth',lw2,'Fontname', 'Arial');

axes('position',[sx+dx+w      sy+2*dy+2*he w he])
    i=ind(1);plot(nvec,speed_FD1(i,:)-speed_base,'.','color',g1,'LineWidth',lw1,'MarkerSize',msize1)
    hold on
    i=ind(2);plot(nvec,speed_FD1(i,:)-speed_base,'.','color',g3,'LineWidth',lw1,'MarkerSize',msize1)
    i=ind(3);plot(nvec,speed_FD1(i,:)-speed_base,'.','color',g2,'LineWidth',lw1,'MarkerSize',msize1)
    line([0 0],[-0.2 0.2],'color','k','LineWidth',lw2)
    text(-0.10,-0.085,'parasite','HorizontalAlignment','center','FontSize',fs3)
    text( 0.12,-0.085,'mutualist','HorizontalAlignment','center','FontSize',fs3)
    axis([-0.25 0.25 -0.1 0.2])
    set(gca,'XTick',-0.2:0.1:0.2)
    set(gca,'FontSize',fs3,'LineWidth',lw2,'Fontname', 'Arial');

%%
load fig4_v.mat
ind = [1 11 19];
axes('position',[sx      sy+dy+he w he])
    i=ind(1);plot(nvec,speed_FD2(i,:)-speed_base,'.','color',g1,'LineWidth',lw1,'MarkerSize',msize1)
    hold on
    i=ind(2);plot(nvec,speed_FD2(i,:)-speed_base,'.','color',g3,'LineWidth',lw1,'MarkerSize',msize1)
    i=ind(3);plot(nvec,speed_FD2(i,:)-speed_base,'.','color',g2,'LineWidth',lw1,'MarkerSize',msize1)
    line([0 0],[-0.2 0.2],'color','k','LineWidth',lw2)
    legend(['v_P = ' num2str(vivec(ind(1)))],['v_P = ' num2str(vivec(ind(2)))],['v_P = ' num2str(vivec(ind(3)))],'Location','NorthWest')
    text(-0.10,-0.085,'parasite','HorizontalAlignment','center','FontSize',fs3)
    text( 0.12,-0.085,'mutualist','HorizontalAlignment','center','FontSize',fs3)
    axis([-0.25 0.25 -0.1 0.2])
    set(gca,'XTick',-0.2:0.1:0.2)
    set(gca,'FontSize',fs3,'LineWidth',lw2,'Fontname', 'Arial');

axes('position',[sx+dx+w sy+dy+he w he])
    i=ind(1);plot(nvec,speed_FD1(i,:)-speed_base,'.','color',g1,'LineWidth',lw1,'MarkerSize',msize1)
    hold on
    i=ind(2);plot(nvec,speed_FD1(i,:)-speed_base,'.','color',g3,'LineWidth',lw1,'MarkerSize',msize1)
    i=ind(3);plot(nvec,speed_FD1(i,:)-speed_base,'.','color',g2,'LineWidth',lw1,'MarkerSize',msize1)
    line([0 0],[-0.2 0.2],'color','k','LineWidth',lw2)
    text(-0.10,-0.085,'parasite','HorizontalAlignment','center','FontSize',fs3)
    text( 0.12,-0.085,'mutualist','HorizontalAlignment','center','FontSize',fs3)
    axis([-0.25 0.25 -0.1 0.2])
    set(gca,'XTick',-0.2:0.1:0.2)
    set(gca,'FontSize',fs3,'LineWidth',lw2,'Fontname', 'Arial');


%%
load fig4_AE.mat
ind = [1 2 3];
axes('position',[sx      sy w he])
    i=ind(1);plot(nvec,speed_DD2(i,:)-speed_base_all(i),'o','color',g1,'LineWidth',lw1,'MarkerSize',msize2)
    hold on
    i=ind(2);plot(nvec,speed_DD2(i,:)-speed_base_all(i),'o','color',g3,'LineWidth',lw1,'MarkerSize',msize2)
    i=ind(3);plot(nvec,speed_DD2(i,:)-speed_base_all(i),'o','color',g2,'LineWidth',lw1,'MarkerSize',msize2)
    line([0 0],[-0.1 0.2],'color','k','LineWidth',lw2)
    legend(['a = ' num2str(avec(ind(1)))],['a = ' num2str(avec(ind(2)))],['a = ' num2str(avec(ind(3)))],'location','northwest')
    text(-0.15,-0.07,'parasite','HorizontalAlignment','center','FontSize',fs3)
    text( 0.15,-0.07,'mutualist','HorizontalAlignment','center','FontSize',fs3)
    axis([-0.25 0.25 -0.1 0.2])
    set(gca,'XTick',-0.2:0.1:0.2)
    set(gca,'FontSize',fs3,'LineWidth',lw2,'Fontname', 'Arial');
    
axes('position',[sx+dx+w sy w he])
    i=ind(1);plot(nvec,speed_DD1(i,:)-speed_base_all(i),'o','color',g1,'LineWidth',lw1,'MarkerSize',msize2)
    hold on
    i=ind(2);plot(nvec,speed_DD1(i,:)-speed_base_all(i),'o','color',g3,'LineWidth',lw1,'MarkerSize',msize2)
    i=ind(3);plot(nvec,speed_DD1(i,:)-speed_base_all(i),'o','color',g2,'LineWidth',lw1,'MarkerSize',msize2)
    line([0 0],[-0.1 0.2],'color','k','LineWidth',lw2)
    text(-0.15,-0.07,'parasite','HorizontalAlignment','center','FontSize',fs3)
    text( 0.15,-0.07,'mutualist','HorizontalAlignment','center','FontSize',fs3)
    axis([-0.25 0.25 -0.1 0.2])
    set(gca,'XTick',-0.2:0.1:0.2)
    set(gca,'FontSize',fs3,'LineWidth',lw2,'Fontname', 'Arial');


% label subpanels
axes('position',[0 0 1 1],'visible','off')
hold on
     line([0.02 0.98],[0.37 0.37],'color','k','LineWidth',lw2)
     line([0.02 0.98],[0.69 0.69],'color','k','LineWidth',lw2)
     text(0.07,     0.11+3*he+2*dy,'a)','horizontalalignment','center')
     text(0.07+w+dx,0.11+3*he+2*dy,'b)','horizontalalignment','center')
     text(0.07,     0.11+2*he+dy,'c)','horizontalalignment','center')
     text(0.07+w+dx,0.11+2*he+dy,'d)','horizontalalignment','center')
     text(0.07,     0.11+he,     'e)','horizontalalignment','center')
     text(0.07+w+dx,0.11+he,     'f)','horizontalalignment','center')
     text(0.03,-0.03+he,       {'net spread','with symbiont'},'horizontalalignment','center','rotation',90)
     text(0.03,-0.03+2*he+dy,  {'net spread','with symbiont'},'horizontalalignment','center','rotation',90)
     text(0.03,-0.03+3*he+2*dy,{'net spread','with symbiont'},'horizontalalignment','center','rotation',90)
     text(0.3,0.03,{'symbiont net effect','(fecundity)'},'horizontalalignment','center')
     text(0.78,0.03,{'symbiont net effect','(survival)'},'horizontalalignment','center')
     set(gca,'FontSize',fs3,'Fontname', 'Arial');
axis([0 1 0 1])


% Backup previous settings
prePaperType = get(hh,'PaperType');
prePaperPosition = get(hh,'PaperPosition');
prePaperSize = get(hh,'PaperSize');

% Make changing paper type possible
set(hh,'PaperType','<custom>');
% Set the page size and position to match the figure's dimensions
position = get(hh,'Position');
set(hh,'PaperPosition',[0,0,position(3:4)]);
set(hh,'PaperSize',position(3:4));

%saveas(1,strcat(['fig3.jpg']))
%print -dpdf -r600 Figure_3.pdf
print -djpeg -r600 fig4.jpg

% Restore the previous settings
set(hh,'PaperType',prePaperType);
set(hh,'PaperPosition',prePaperPosition);
set(hh,'PaperSize',prePaperSize);