clear all

load('DataLatiGradPartialr0.mat','chngpars','partialr0','parnames','par0values','popthrhd','OutData'); 

%%
level=1;
popthrhdnmbr=length(popthrhd);
columns=[1:5,5+(level:popthrhdnmbr:6*popthrhdnmbr), (5+6*popthrhdnmbr+1):length(OutData(1,:))];

pta0=min(OutData(:,2));
pta1=max(OutData(:,2));
ptb=min(OutData(:,3));
ptc=max(OutData(:,4));
NN=max(OutData(:,1));
indx=(OutData(:,1)<=NN & OutData(:,2)>pta0-1e-4 & OutData(:,2)<pta1+1e-4 ...
    & OutData(:,3)<ptb+1e-4 & OutData(:,3)>ptb-1e-4...
    & OutData(:,4)<ptc+1e-4 & OutData(:,4)>ptc-1e-4); 
plotOutData=OutData(indx,columns);


nmbrofruns=0;
r0length=sum((plotOutData(:,1)==plotOutData(1,1) & plotOutData(:,3)==plotOutData(1,3) & plotOutData(:,4)==plotOutData(1,4)));
idinit=max(floor(plotOutData(end,1)*rand(1))-nmbrofruns,0)*r0length;
indx=idinit+1:idinit+min(plotOutData(end,1),nmbrofruns)*r0length;
rn=floor(rand(1)*plotOutData(end,1));
rn=rn-1;
%rn=10;
indx1=(OutData(:,1)==rn & plotOutData(:,3)==plotOutData(1,3) & plotOutData(:,4)==plotOutData(1,4));

stdon=1; % binary.

bmscale=20;
BinNmbr=floor(sum(OutData(:,1)==1)/2);
Binsize=(log(max(OutData(:,2)))/log(10)-log(min(OutData(:,2)))/log(10))/BinNmbr;%30;


hold on

%%
Bms=plotOutData(:,8)+plotOutData(:,6)+plotOutData(:,7)+1e-6;

yBms=log(plotOutData(:,2))/log(10);

yyBms=yBms(yBms>-Inf);
yyBms=sort(yyBms);
yBmsm=max([yyBms(1), min(yBms)]);
yBmsM=max(yBms);
yBinsize=Binsize;

yBmsBins=yBmsm:yBinsize:yBmsM;


yzpms=[];
y1nmbr=[];
z1nmbr=[];
p1nmbr=[];
yzpstd=[];
y1std=[];
z1std=[];
p1std=[];

pbms=[];
hbms=[];
cbms=[];
pstd=[];
hstd=[];
cstd=[];

pendngrdmean=[];
hendngrdmean=[];
cendngrdmean=[];

pcompetitivemean=[];
hcompetitivemean=[];
ccompetitivemean=[];

meanpoprate=[];
stdpoprate=[];
maxpoprate=[];

pendngrdstd=[];
hendngrdstd=[];
cendngrdstd=[];

pcompetitivestd=[];
hcompetitivestd=[];
ccompetitivestd=[];

plotOutData1=[];

plotOutData1(:,6:16)=plotOutData(:,6:16);

for i=yBmsBins
    ind1=(yBms>=i & yBms<i+yBinsize);    
    pbms=[pbms,mean(plotOutData1(ind1,6))];
    hbms=[hbms,mean(plotOutData1(ind1,7))];
    cbms=[cbms,mean(plotOutData1(ind1,8))];
    pstd=[pstd,std(plotOutData1(ind1,6))];
    hstd=[hstd,std(plotOutData1(ind1,7))];
    cstd=[cstd,std(plotOutData1(ind1,8))];
    y1nmbr=[y1nmbr, mean(plotOutData(ind1,9))];
    z1nmbr=[z1nmbr, mean(plotOutData(ind1,10))];
    p1nmbr=[p1nmbr, mean(plotOutData(ind1,11))];
    yzpms=[yzpms, mean(Bms(ind1))];
    yzpstd=[yzpstd, std(Bms(ind1))];
    %yzpstd=[yzpstd, std(log(Bms(ind1))/log(10))];
    y1std=[y1std, std(plotOutData(ind1,9))];
    z1std=[z1std, std(plotOutData(ind1,10))];
    p1std=[p1std, std(plotOutData(ind1,11))];
    
    pendngrdmean=[pendngrdmean, mean(plotOutData(ind1,12))];
    pendngrdstd=[pendngrdstd, std(plotOutData(ind1,12))];
    
    hendngrdmean=[hendngrdmean, mean(plotOutData(ind1,13))];
    hendngrdstd=[hendngrdstd, std(plotOutData(ind1,13))];

    cendngrdmean=[cendngrdmean, mean(plotOutData(ind1,14))];
    cendngrdstd=[cendngrdstd, std(plotOutData(ind1,14))];

    pcompetitivemean=[pcompetitivemean, mean(plotOutData(ind1,15))];
    pcompetitivestd=[pcompetitivestd, std(plotOutData(ind1,15))];

    hcompetitivemean=[hcompetitivemean, mean(plotOutData(ind1,16))];
    hcompetitivestd=[hcompetitivestd, std(plotOutData(ind1,16))];

    ccompetitivemean=[ccompetitivemean, mean(plotOutData(ind1,17))];
    ccompetitivestd=[ccompetitivestd, std(plotOutData(ind1,17))];
    
    meanpoprate=[meanpoprate, mean(plotOutData(ind1,18))];
    stdpoprate=[stdpoprate, std(plotOutData(ind1,18))];
    maxpoprate=[maxpoprate, mean(plotOutData(ind1,19))];


end


yzpms=log(yzpms)/log(10);
yzpstd=log(yzpstd)/log(10);

%%
figure(2)
hold off

xaxispts=log(plotOutData(indx,2))/log(10);
plot([-8],[0],'kv',[-8],[-1],'ks',[-8],[-2],'ko',[-8],[-3],'k^',[-8],[-4],'k+')
legend('Biomass','Plant','Herbivore','Carnivore','Total','location','nw')
xlabel('log(r_0)','fontsize',16)
ylabel('Number of Species','fontsize',16)

    
hold on


plot(yBmsBins+yBinsize/2,y1nmbr,'ks',yBmsBins+yBinsize/2,z1nmbr,'ko',...
    yBmsBins+yBinsize/2,p1nmbr,'k^',yBmsBins+yBinsize/2,y1nmbr+z1nmbr+p1nmbr,'m-',...
    yBmsBins+yBinsize/2,y1nmbr,'g-',yBmsBins+yBinsize/2,z1nmbr,'b-',...
    yBmsBins+yBinsize/2,p1nmbr,'r-','linewidth', 2.5)
hold on
plot(yBmsBins+yBinsize/2,y1nmbr+z1nmbr+p1nmbr,'k+',...
    'markersize',10,'linewidth', 2.5)

if stdon==1
hold on
for j=1:length(yBmsBins)
    plot([yBmsBins(j)+yBinsize/2 yBmsBins(j)+yBinsize/2],...
        [z1nmbr(j)+z1std(j) z1nmbr(j)-z1std(j)], 'b-','linewidth',1.5)
end

for j=1:length(yBmsBins)
    plot([yBmsBins(j)+yBinsize/2 yBmsBins(j)+yBinsize/2],...
        [y1nmbr(j)+y1std(j) y1nmbr(j)-y1std(j)], 'g.',...
        [yBmsBins(j)+yBinsize/2 yBmsBins(j)+yBinsize/2],...
        [p1nmbr(j)+p1std(j) p1nmbr(j)-p1std(j)], 'r-')
end

end

%axis([yBmsm yBmsM 0 min(180,max(y1nmbr+z1nmbr+p1nmbr))])
axis([yBmsm yBmsM 0 180])

%grid on
box off

set(gca,'XTick',yBmsm:1:yBmsM)

ax1 = gca;
set(ax1,'XColor','k','YColor','k')

ax2 = axes('Position',get(ax1,'Position'),... 
           'XAxisLocation','top',...
           'YAxisLocation','right',...
           'Color','none',...
           'XColor','k','YColor','k');
hold on


plot(yBmsBins+yBinsize/2,yzpms,'kv',yBmsBins+yBinsize/2,yzpms,'y-','linewidth', 2.5,'Parent',ax2)
    if stdon==2
    for j=1:length(yBmsBins)
        plot([yBmsBins(j)+yBinsize/2 yBmsBins(j)+yBinsize/2],[yzpms(j)+yzpstd(j) yzpms(j)-yzpstd(j)], 'kx')
    end
    end

ylabel('log(Web Biomass Mean)','fontsize',16)

%axis([yBmsm yBmsM 0 1.1*max(yzpms)])
axis([yBmsm yBmsM -3 3])

yend=5;
%xlimits = get(ax1,'XLim');
ylimits = get(ax1,'YLim');
%xinc = (xlimits(2)-xlimits(1))/yend;
yinc = (ylimits(2)-ylimits(1))/yend;

%set(ax1,'XTick',[xlimits(1):xinc:xlimits(2)],...
%        'YTick',[ylimits(1):yinc:ylimits(2)])

set(ax1,'YTick',[ylimits(1):yinc:ylimits(2)])        
%%
figure(1)
hold off
nb=1;
subplot(3,1,1)
hold off
%plot([0],[-8],'gs')
hold on
%plot([1],[-8],'ks','markersize',8)
%hold on
plot([2],[-8],'kx','markersize',10)
%legend('Living','Competitve','fontsize',16,'location','e')
legend('Secondary Speciation Pool','fontsize',16,'location','e')

text(-1.75, 50, 'Plant','fontsize',12)
Box

hold on
plot(yBmsBins+yBinsize/2,y1nmbr,'gs',yBmsBins+yBinsize/2,y1nmbr,'g-')
hold on
plot(yBmsBins+yBinsize/2,pcompetitivemean,'kx',yBmsBins+yBinsize/2,pcompetitivemean,'k-','markersize',10,'linewidth',1)

if stdon==nb
hold on
for j=1:length(yBmsBins)
    plot([yBmsBins(j)+yBinsize/2 yBmsBins(j)+yBinsize/2],...
        [pcompetitivemean(j)+pcompetitivestd(j) pcompetitivemean(j)-pcompetitivestd(j)], 'k-')
end
end
axis([yBmsm yBmsM 0 1.25*max([y1nmbr,pcompetitivemean])])


subplot(3,1,2)
hold off
%plot([0],[-8],'bo')
%hold on
%plot([0],[-8],'k.','markersize',18)
%legend('Living Herbivore','Endangered Herbivore','fontsize',16,'location','nw')

%plot([2],[-8],'m*','markersize',10)
%legend('Living Plant','Endangered Plant','Adjusted Plant','fontsize',16,'location','nw')
%legend('Endangered','Competitve','fontsize',16,'location','ne')
text(-1.75, 150, 'Herbivore','fontsize',12)
Box

hold on
plot(yBmsBins+yBinsize/2,y1nmbr,'gs',yBmsBins+yBinsize/2,y1nmbr,'g-')
hold on
plot(yBmsBins+yBinsize/2,z1nmbr,'bo',yBmsBins+yBinsize/2,z1nmbr,'b-')
hold on
plot(yBmsBins+yBinsize/2,hcompetitivemean,'kx',yBmsBins+yBinsize/2,hcompetitivemean,'k-','markersize',10,'linewidth',1)

if stdon==nb
hold on
for j=1:length(yBmsBins)
    plot([yBmsBins(j)+yBinsize/2 yBmsBins(j)+yBinsize/2],...
        [hcompetitivemean(j)+hcompetitivestd(j) hcompetitivemean(j)-hcompetitivestd(j)], 'k-')
end
end
axis([yBmsm yBmsM 0 1.25*max([y1nmbr,z1nmbr,hcompetitivemean])])


subplot(3,1,3)
hold off
%plot([0],[-8],'r^')
%hold on
%plot([0],[-8],'k.','markersize',18)
%legend('Living Carnivore','Endangered Carnivore','fontsize',16,'location','nw')
%hold on

%plot([2],[-8],'m*','markersize',10)
%legend('Living Plant','Endangered Plant','Adjusted Plant','fontsize',16,'location','nw')
%legend('Endangered','Competitve','fontsize',16,'location','nw')
text(-1.75, 85, 'Carnivore','fontsize',12)
Box

hold on
plot(yBmsBins+yBinsize/2,z1nmbr,'bo',yBmsBins+yBinsize/2,z1nmbr,'b-')
hold on
plot(yBmsBins+yBinsize/2,p1nmbr,'r^',yBmsBins+yBinsize/2,p1nmbr,'r-')
hold on
plot(yBmsBins+yBinsize/2,ccompetitivemean,'kx',yBmsBins+yBinsize/2,ccompetitivemean,'k-','markersize',10,'linewidth',1)

if stdon==nb
hold on
for j=1:length(yBmsBins)
    plot([yBmsBins(j)+yBinsize/2 yBmsBins(j)+yBinsize/2],...
        [ccompetitivemean(j)+ccompetitivestd(j) ccompetitivemean(j)-ccompetitivestd(j)], 'k-')
end
end
axis([yBmsm yBmsM 0 1.25*max([z1nmbr,p1nmbr,ccompetitivemean])])

xlabel('log(r_0)','fontsize',16)

%return
%%
figure(3)
hold off
subplot(2,1,1)
    hold off
    plot([-8],[0],'ks',[-8],[0],'ko',[-8],[0],'k^')
legend('Plant','Herbivore','Carnivore','location','nw')
%pbms=log(pbms)/log(10);hbms=log(hbms)/log(10);cbms=log(cbms)/log(10);
%pstd=log(pstd)/log(10);hstd=log(hstd)/log(10);cstd=log(cstd)/log(10);
hold on
    plot(yBmsBins+yBinsize/2,pbms,'ks',...
        yBmsBins+yBinsize/2,pbms,'g-',...
        yBmsBins+yBinsize/2,hbms,'ko',...
        yBmsBins+yBinsize/2,hbms,'b-',...
        yBmsBins+yBinsize/2,cbms,'k^',...
        yBmsBins+yBinsize/2,cbms,'r-', 'linewidth', 2.5)
    if stdon==1
    for j=1:length(yBmsBins)
        plot([yBmsBins(j)+yBinsize/2 yBmsBins(j)+yBinsize/2],...
            [pbms(j)+pstd(j) pbms(j)-pstd(j)], 'g-',...
            [yBmsBins(j)+yBinsize/2 yBmsBins(j)+yBinsize/2],...
            [hbms(j)+hstd(j) hbms(j)-hstd(j)], 'b-',...
            [yBmsBins(j)+yBinsize/2 yBmsBins(j)+yBinsize/2],...
            [cbms(j)+cstd(j) cbms(j)-cstd(j)], 'r-','linewidth',1.5)
    end
    end

ylabel('Biomass','fontsize',16)
axis([yBmsm yBmsM 0 10])

subplot(2,1,2)
    hold off
pbms=log(pbms+1e-6)/log(10);hbms=log(hbms+1e-6)/log(10);cbms=log(cbms+1e-6)/log(10);

scl=1;
pstd=scl*pstd;hstd=scl*hstd;cstd=scl*cstd;

    plot(yBmsBins+yBinsize/2,pbms,'ks',...
        yBmsBins+yBinsize/2,pbms,'g-',...
        yBmsBins+yBinsize/2,hbms,'ko',...
        yBmsBins+yBinsize/2,hbms,'b-',...
        yBmsBins+yBinsize/2,cbms,'k^',...
        yBmsBins+yBinsize/2,cbms,'r-', 'linewidth', 2.5)
    hold on
    if stdon==5
    for j=1:length(yBmsBins)
        plot([yBmsBins(j)+yBinsize/2 yBmsBins(j)+yBinsize/2],...
            [pbms(j)+pstd(j) pbms(j)-pstd(j)], 'g-',...
            [yBmsBins(j)+yBinsize/2 yBmsBins(j)+yBinsize/2],...
            [hbms(j)+hstd(j) hbms(j)-hstd(j)], 'b-',...
            [yBmsBins(j)+yBinsize/2 yBmsBins(j)+yBinsize/2],...
            [cbms(j)+cstd(j) cbms(j)-cstd(j)], 'r-','linewidth',1.5)
    end
    end

xlabel('log(r_0)','fontsize',16)
ylabel('log(Biomass Mean)','fontsize',16)
axis([yBmsm yBmsM -6 6])

%%
figure(4)
nb=1;
hold off
subplot(3,1,1)
hold off
%plot([0],[-8],'gs')
hold on
plot([1],[-8],'k.','markersize',18)
hold on
plot([2],[-8],'m*','markersize',10)
%legend('Living Plant','Endangered Plant','Adjusted Plant','fontsize',16,'location','nw')
legend('Endangered','Competitve','fontsize',16,'location','e')
text(-1.5, 30, 'Plant','fontsize',12)
Box

hold on
plot(yBmsBins+yBinsize/2,y1nmbr,'gs',yBmsBins+yBinsize/2,y1nmbr,'g-')
hold on
plot(yBmsBins+yBinsize/2,pendngrdmean,'k.',yBmsBins+yBinsize/2,pendngrdmean,'k-','markersize',18,'linewidth',2.5)

hold on
plot(yBmsBins+yBinsize/2,y1nmbr-pendngrdmean,'m*',yBmsBins+yBinsize/2,y1nmbr-pendngrdmean,'m-','markersize',10,'linewidth',1)


if stdon==nb
hold on
for j=1:length(yBmsBins)
    plot([yBmsBins(j)+yBinsize/2 yBmsBins(j)+yBinsize/2],...
        [pendngrdmean(j)+pendngrdstd(j) pendngrdmean(j)-pendngrdstd(j)], 'k-')
end
end
axis([yBmsm yBmsM 0 1.25*max(y1nmbr)])


subplot(3,1,2)
hold off
%plot([0],[-8],'bo')
%hold on
%plot([0],[-8],'k.','markersize',18)
%legend('Living Herbivore','Endangered Herbivore','fontsize',16,'location','nw')

%plot([2],[-8],'m*','markersize',10)
%legend('Living Plant','Endangered Plant','Adjusted Plant','fontsize',16,'location','nw')
%legend('Endangered','Competitve','fontsize',16,'location','ne')
text(-1.5, 50, 'Herbivore','fontsize',12)
Box

hold on
plot(yBmsBins+yBinsize/2,z1nmbr,'bo',yBmsBins+yBinsize/2,z1nmbr,'b-')
hold on
plot(yBmsBins+yBinsize/2,hendngrdmean,'k.',yBmsBins+yBinsize/2,hendngrdmean,'k-','markersize',18,'linewidth',2.5)

hold on
plot(yBmsBins+yBinsize/2,z1nmbr-hendngrdmean,'m*',yBmsBins+yBinsize/2,z1nmbr-hendngrdmean,'m-','markersize',10,'linewidth',1)

if stdon==nb
hold on
for j=1:length(yBmsBins)
    plot([yBmsBins(j)+yBinsize/2 yBmsBins(j)+yBinsize/2],...
        [hendngrdmean(j)+hendngrdstd(j) hendngrdmean(j)-hendngrdstd(j)], 'k-')
end
end
axis([yBmsm yBmsM 0 1.25*max(z1nmbr)])



subplot(3,1,3)
hold off
%plot([0],[-8],'r^')
%hold on
%plot([0],[-8],'k.','markersize',18)
%legend('Living Carnivore','Endangered Carnivore','fontsize',16,'location','nw')
%hold on

%plot([2],[-8],'m*','markersize',10)
%legend('Living Plant','Endangered Plant','Adjusted Plant','fontsize',16,'location','nw')
%legend('Endangered','Competitve','fontsize',16,'location','nw')
text(-1.5, 30, 'Carnivore','fontsize',12)
Box

hold on
plot(yBmsBins+yBinsize/2,p1nmbr,'r^',yBmsBins+yBinsize/2,p1nmbr,'r-')
hold on
plot(yBmsBins+yBinsize/2,cendngrdmean,'k.',yBmsBins+yBinsize/2,cendngrdmean,'k-','markersize',18,'linewidth',2.5)

hold on
plot(yBmsBins+yBinsize/2,p1nmbr-cendngrdmean,'m*',yBmsBins+yBinsize/2,p1nmbr-cendngrdmean,'m-','markersize',10,'linewidth',1)

plot(yBmsBins+yBinsize/2,p1nmbr+y1nmbr+z1nmbr-cendngrdmean-pendngrdmean-hendngrdmean,'r*',yBmsBins+yBinsize/2,p1nmbr+y1nmbr+z1nmbr-cendngrdmean-pendngrdmean-hendngrdmean,'r-','markersize',10,'linewidth',1)


if stdon==nb
hold on
for j=1:length(yBmsBins)
    plot([yBmsBins(j)+yBinsize/2 yBmsBins(j)+yBinsize/2],...
        [cendngrdmean(j)+cendngrdstd(j) cendngrdmean(j)-cendngrdstd(j)], 'k-')
end
end
axis([yBmsm yBmsM 0 1.25*max(p1nmbr)])
axis([yBmsm yBmsM 0 4*max(p1nmbr)])
xlabel('log(r_0)','fontsize',16)

%%
figure(5)
hold off
subplot(2,1,1)
hold off
plot(yBmsBins+yBinsize/2,maxpoprate,'r.','markersize',18)
legend('Max. |Growth Rate|','fontsize',16,'location','nw')
hold on
plot(yBmsBins+yBinsize/2,maxpoprate,'r-','linewidth',2.5,'markersize',3)
axis([yBmsm yBmsM 0 1.25*max(maxpoprate)])
  
subplot(2,1,2)
hold off
plot(yBmsBins+yBinsize/2,meanpoprate,'b.','markersize',18)
legend('Mean |Growth Rate|','fontsize',16,'location','nw')
hold on
plot(yBmsBins+yBinsize/2,meanpoprate,'b-','linewidth',2.5,'markersize',3)
hold on
ns=1;
if stdon==ns
hold on
for j=1:length(yBmsBins)
    plot([yBmsBins(j)+yBinsize/2 yBmsBins(j)+yBinsize/2],...
        [meanpoprate(j)+stdpoprate(j) meanpoprate(j)-stdpoprate(j)], 'k-')
end
end

if stdon==ns
axis([yBmsm yBmsM 0 1.25*max(stdpoprate)])
else
axis([yBmsm yBmsM 0 1.1*max(meanpoprate)])
end

    
xlabel('log(r_0)','fontsize',16)

%%
figure(6)
hold off
plot([-8],[0],'ks',[-8],[0],'ko',[-8],[0],'k^')
legend('Plant','Herbivore','Carnivore','location','nw')

hold on

plot(yBmsBins+yBinsize/2,pendngrdmean./y1nmbr*100,'ks',yBmsBins+yBinsize/2,pendngrdmean./y1nmbr*100,'g-','markersize',7,'linewidth',2.5)
hold on
plot(yBmsBins+yBinsize/2,hendngrdmean./z1nmbr*100,'ko',yBmsBins+yBinsize/2,hendngrdmean./z1nmbr*100,'b-','markersize',7,'linewidth',2.5)
hold on
plot(yBmsBins+yBinsize/2,cendngrdmean./p1nmbr*100,'k^',yBmsBins+yBinsize/2,cendngrdmean./p1nmbr*100,'r-','markersize',7,'linewidth',2.5)
xlabel('log(r_0)','fontsize',16)
ylabel('Percentage of Endangered Species','fontsize',16)
axis([yBmsm yBmsM 0 60])

%%
figure(8)
hold off

subplot(2,1,1)
plot([-8],[0],'ks',[-8],[1],'ko',[-8],[2],'k^',[-8],[3],'k*')
legend('Plant','Herbivore','Carnivore','Total','location','nw')

compplant=y1nmbr-pendngrdmean;
compherbivore=z1nmbr-hendngrdmean;
compcarivore=p1nmbr-cendngrdmean;
hold on

plot(yBmsBins+yBinsize/2,compplant,'ks',yBmsBins+yBinsize/2,compplant,'g-','markersize',7,'linewidth',2.5)
hold on
plot(yBmsBins+yBinsize/2,compherbivore,'ko',yBmsBins+yBinsize/2,compherbivore,'b-','markersize',7,'linewidth',2.5)
hold on
plot(yBmsBins+yBinsize/2,compcarivore,'k^',yBmsBins+yBinsize/2,compcarivore,'r-','markersize',7,'linewidth',2.5)
hold on
plot(yBmsBins+yBinsize/2,compcarivore+compherbivore+compplant,'k*',yBmsBins+yBinsize/2,compcarivore+compherbivore+compplant,'m-','markersize',7,'linewidth',2.5)


ylabel('Competitive Species','fontsize',12)
%text(-1.5, 80, 'Competitive Species','fontsize',12)
%title('Percentage of Endangered Species','fontsize',16)


axis([yBmsm yBmsM 0 80])

subplot(2,1,2)
hold off

plot([0],[-8],'b.','markersize',18)
hold on
plot([0],[-8],'bo')
legend('Mean |Growth Rate| in magnified scale','Mean |Growth Rate| in full scale','fontsize',16,'location','nw')

hold on
plot(yBmsBins+yBinsize/2,meanpoprate,'bo')
hold on
plot(yBmsBins+yBinsize/2,meanpoprate,'b-')
hold on
ns=1;
if stdon==ns
hold on
for j=1:length(yBmsBins)
    plot([yBmsBins(j)+yBinsize/2 yBmsBins(j)+yBinsize/2],...
        [meanpoprate(j)+stdpoprate(j) meanpoprate(j)-stdpoprate(j)], 'k-')
end
end

if stdon==ns
%axis([yBmsm yBmsM 0 1.25*max(stdpoprate)])
else
%axis([yBmsm yBmsM 0 1.1*max(meanpoprate)])
end

axis([yBmsm yBmsM 0 .005])

box off

%set(gca,'XTick',yBmsm:1:yBmsM)
%set(gca,'YTick',0:.1:.2)

set(gca,'XTick',-3:20:100,'YTick',0:.0025:.005)


ax1 = gca;
set(ax1,'XColor','k','YColor','k')

ax2 = axes('Position',get(ax1,'Position'),... 
            'XAxisLocation','bottom',...
           'YAxisLocation','right',...
           'Color','none',...
           'XColor','k','YColor','k');
hold on

plot(yBmsBins+yBinsize/2,meanpoprate,'b.','markersize',18)
hold on
plot(yBmsBins+yBinsize/2,meanpoprate,'b-','linewidth',2.5,'markersize',3)

plot([yBmsm yBmsM],[.008 .008],'k-')
%axis([yBmsm yBmsM 0 1.1*max(yzpms)])
axis([yBmsm yBmsM 0 .0006])

xlabel('log(r_0)','fontsize',16)

yend=5;
%xlimits = get(ax1,'XLim');
ylimits = get(ax1,'YLim');
%xinc = (xlimits(2)-xlimits(1))/yend;
yinc = (ylimits(2)-ylimits(1))/yend;

%set(ax1,'XTick',[xlimits(1):xinc:xlimits(2)],...
%        'YTick',[ylimits(1):yinc:ylimits(2)])

%set(ax1,'YTick',[ylimits(1):yinc:ylimits(2)])        
%%
figure(20)
hold off

subplot(3,1,1)
hold off
%plot([-8],[0],'ks',[-8],[-1],'ko',[-8],[-2],'k^')
%legend('Plant','Herbivore','Carnivore','location','nw')

scl=1;
pstd=scl*pstd;hstd=scl*hstd;cstd=scl*cstd;

    plot(yBmsBins+yBinsize/2,pbms,'ks',...
        yBmsBins+yBinsize/2,pbms,'g-',...
        yBmsBins+yBinsize/2,hbms,'ko',...
        yBmsBins+yBinsize/2,hbms,'b-',...
        yBmsBins+yBinsize/2,cbms,'k^',...
        yBmsBins+yBinsize/2,cbms,'r-', 'linewidth', 2.5)
    hold on
    if stdon==5
    for j=1:length(yBmsBins)
        plot([yBmsBins(j)+yBinsize/2 yBmsBins(j)+yBinsize/2],...
            [pbms(j)+pstd(j) pbms(j)-pstd(j)], 'g-',...
            [yBmsBins(j)+yBinsize/2 yBmsBins(j)+yBinsize/2],...
            [hbms(j)+hstd(j) hbms(j)-hstd(j)], 'b-',...
            [yBmsBins(j)+yBinsize/2 yBmsBins(j)+yBinsize/2],...
            [cbms(j)+cstd(j) cbms(j)-cstd(j)], 'r-','linewidth',1.5)
    end
    end

%text(-1.75, 3.5, 'log(Biomass Mean)','fontsize',12)
text(2.75, -4, 'log(Biomass Mean)','fontsize',12)
axis([yBmsm yBmsM -6 3])


subplot(3,1,2)
hold off

plot(yBmsBins+yBinsize/2,pendngrdmean./y1nmbr*100,'ks',yBmsBins+yBinsize/2,pendngrdmean./y1nmbr*100,'g-','markersize',7,'linewidth',2.5)
hold on
plot(yBmsBins+yBinsize/2,hendngrdmean./z1nmbr*100,'ko',yBmsBins+yBinsize/2,hendngrdmean./z1nmbr*100,'b-','markersize',7,'linewidth',2.5)
hold on
plot(yBmsBins+yBinsize/2,cendngrdmean./p1nmbr*100,'k^',yBmsBins+yBinsize/2,cendngrdmean./p1nmbr*100,'r-','markersize',7,'linewidth',2.5)
%xlabel('log(r_0)','fontsize',16)
text(1,50,'Endangered Species (%)','fontsize',12)
axis([yBmsm yBmsM 0 60])


subplot(3,1,3)
hold off

plot(yBmsBins+yBinsize/2,meanpoprate,'bo')
hold on
plot(yBmsBins+yBinsize/2,meanpoprate,'b-')
hold on
ns=1;
if stdon==ns
hold on
for j=1:length(yBmsBins)
    plot([yBmsBins(j)+yBinsize/2 yBmsBins(j)+yBinsize/2],...
        [meanpoprate(j)+stdpoprate(j) meanpoprate(j)-stdpoprate(j)], 'k-')
end
end

axis([yBmsm yBmsM 0 .0001])
text(-1.75, .00007, 'Mean |Growth Rate|','fontsize',12)
xlabel('log(r_0)','fontsize',16)

return
%%
figinmass

return