% Figure making loop for Rostock workshop % for output from Nstochseq_rostock07_workshop % October 2007 %this will work for up to 12 environmental states % % % the limiting factor is the no. of rows of the plotsyms matrix % another limiting factor is the no. of columns of the stuff matrix...this % program will work in that sense up to and including 99 environmental states close all clear all load AE_base load AE_Markov load AE_survmarkov plotsyms=['b ';'g ';'r ';'c ';'m ';'y ';'b:';'g:';'r:';'c:';'m:';'y:']; for i=1:nstates if i<10 stuff1(i,:)=['initial state ' num2str(i)]; %pads the spaces so we can then have two digits stuff2(i,:)=['constant state ' num2str(i)]; stuff3(i,:)=['state ' num2str(i)]; xvalues2(i,:)=[' ' num2str(i)]; %string labels xtick2(i)=i; %numeric values else stuff1(i,:)=['initial state ' num2str(i)]; stuff2(i,:)=['constant state ' num2str(i)]; stuff3(i,:)=['state ' num2str(i)]; xvalues2(i,:)=[num2str(i)]; %string labels xtick2(i)=i; %numeric values end end; stuff1=[stuff1 'plateau ']; stuff2=[stuff2 'constant mean ']; for i=1:nstages if i<10 stagelegend(i,:)=['stage ' num2str(i)]; %pads the spaces so we can then have two digits xvalues1(i,:)=[' ' num2str(i)]; %string labels xtick1(i)=i; %numeric values else stagelegend(i,:)=['stage ' num2str(i)]; xvalues1(i,:)=[num2str(i)]; %string labels xtick1(i)=i; %numeric values end ; end; figure(1) subplot(2,1,1) for i=1:nstates plot(mu_markov(i,:),plotsyms(i,:),'linewidth',2); hold on; end; plot(repmat(plateau_markov,1,maxage),'k','linewidth',2); legend(stuff1); %text(maxage/10,1.2*slope_markov,['-log(\lambda)']) title(['Markov environment, ' name(1,:), '\it{-log \lambda_{m}} = ' num2str(plateau_markov) ]); ylabel('Mortality rate, \it{\mu_{a}(x)}','FontName','Helvetica','FontSize',16); %xlabel('Age{\it x}, yrs','FontName','Helvetica','FontSize',16); axis( [0 maxage min(min(mu_markov)) max(max(mu_markov))] ); hold off; subplot(2,1,2) for i=1:nstates plot(qcon_mu(i,:),plotsyms(i,:),'linewidth',2); hold on; end; plot(qbar_mu,'k','linewidth', 2) legend(stuff2); title(['Deterministic environment, \it{-log \lambda_{qbar}}= ' num2str(qbar_plateau)]) ylabel('Mortality rate, \it{\mu_x}','FontName','Helvetica','FontSize',16); xlabel('Age{\it x}, yrs','FontName','Helvetica','FontSize',16); axis( [0 maxage min(min(mu_markov)) max(max(mu_markov))] ); hold off; figure(2) bar(qbar_deaths(1,:)) title(['Deterministic environment: ' stuff2(end,:)]) ylabel('Proportion of Deaths','FontName','Helvetica','FontSize',16); xlabel('Age{\it x}, yrs','FontName','Helvetica','FontSize',16); axis( [0 maxage/3 0 max(max(deaths_markov))]); for i=1:nstates figure(2+i) bar(deaths_markov(i,:)) title(['Markov environment: ' stuff1(i,:)]) ylabel('Proportion of Deaths','FontName','Helvetica','FontSize',16); xlabel('Age{\it x}, yrs','FontName','Helvetica','FontSize',16); axis( [0 maxage/3 0 max(max(deaths_markov))]); end figure bar(lifeexp_markov'); ylabel('Remaining life expectancy, yrs') title(['Markov environment']) legend(stuff1(1:nstates,:)) xlabel('stage') figure; subplot(2,1,1) barh(us_markov','stacked'); legend(stagelegend); ylabel('State') xlabel('Proportion in dominant eigenvector') subplot(2,1,2) barh(u_markov) ylabel('Stage') xlabel('Proportion in dominant eigenvector') figure %xtick=[1 2 3 4 5 6 7 8]; %xvalues=['seed ';'sdling ';'juvenile ';'pre-rep ';'smallrep ';'medrep ';'largerep ';'xlargerep']; % ares only bar(qcon_oneperiodsurvival'); ylabel('One period survival') legend(stuff3(1:nstates,:)) %set(gca,'XTick',xtick); %ares only %set(gca,'XTickLabel',{xvalues},'FontName','Helvetica','FontSize',14) xlabel('Stage') figure subplot(1,2,2) bar(pis) ylabel('Frequency','FontName','Helvetica','FontSize',16); xlabel('Habitat state','FontName','Helvetica','FontSize',16); subplot(1,2,1) compass(hab_eigs); title([name(1,:)]) %dot patterns for demography in each environmental state for kk=1:nstates;% starts the loop over states mat= qs(:,:,kk); % the first q matrix is in when kk=1 dotsize=[100 85 70 55 40 25 10 5 1]; %defines dot sizes dotsize=dotsize/2; %rescale for multiple subplots % get the structure of the matrix by transition magnitude mats=zeros(nstages,nstages,length(dotsize)); mats(:,:,1) = mat>=1; mats(:,:,2) = (mat>=.75 & mat<1); mats(:,:,3) = (mat>=.50 & mat<.75); mats(:,:,4) = (mat>=.25 & mat<.5); mats(:,:,5) = (mat>=.1 & mat<.25); mats(:,:,6) = (mat>=0.01 & mat<.1); mats(:,:,7) = (mat>=0.001 & mat<.01); mats(:,:,8) = (mat>=0.0001 & mat<.001); mats(:,:,9) = (mat<0.0001 & mat>0); matdiag = eye(nstages); figure %since the brujo plot matrices in positions 5-8, %subplot(2,2,b-4) for i=1:length(dotsize) %spy(mats(:,:,i),dotsize(i),'k'); %makes the dots black, does not work in %MATLAB 7 spy(mats(:,:,i),dotsize(i)); hold on; end; %spy(matdiag,10,'w+'); %mark the diagonal with white plus text(5,1,[stuff3(kk,:)]); %xvalues=['1';'2';'3';'4';'5';'6';'7';'8']; now defined at outset set(gca,'XTick',xtick1); set(gca,'XTickLabel',{xvalues1},'FontName','Helvetica','FontSize',10) set(gca,'YTick',xtick1); set(gca,'YTickLabel',{xvalues1},'FontName','Helvetica','FontSize',10) xlabel('Stage at time {\it t}','FontName','Helvetica','FontSize',12) ylabel('Stage at time {\it t+1}','FontName','Helvetica','FontSize',12) hold off; end; %ends the loop over states %dot patterns for habitat transitions mat= cmat; % the habitat transition matrix dotsize=[100 85 70 55 40 25 10 5 1]; %defines dot sizes dotsize=dotsize/2; %rescale for multiple subplots % get the structure of the matrix mats=zeros(nstates,nstates,length(dotsize)); mats(:,:,1) = mat>=1; mats(:,:,2) = (mat>=.75 & mat<1); mats(:,:,3) = (mat>=.50 & mat<.75); mats(:,:,4) = (mat>=.25 & mat<.5); mats(:,:,5) = (mat>=.1 & mat<.25); mats(:,:,6) = (mat>=0.01 & mat<.1); mats(:,:,7) = (mat>=0.001 & mat<.01); mats(:,:,8) = (mat>=0.0001 & mat<.001); mats(:,:,9) = (mat<0.0001 & mat>0); matdiag = eye(nstages); figure for i=1:length(dotsize) %spy(mats(:,:,i),dotsize(i),'k'); %makes the dots black, does not work in %MATLAB 7 spy(mats(:,:,i),dotsize(i)); hold on; end; %spy(matdiag,10,'w+'); %mark the diagonal with white plus text(5,1,['Habitat transitions']); %xvalues=['1';'2';'3';'4';'5';'6';'7';'8']; now defined at outset set(gca,'XTick',xtick2); set(gca,'XTickLabel',{xvalues2},'FontName','Helvetica','FontSize',10) set(gca,'YTick',xtick2); set(gca,'YTickLabel',{xvalues2},'FontName','Helvetica','FontSize',10) xlabel('State at time {\it t}','FontName','Helvetica','FontSize',12) ylabel('State at time {\it t+1}','FontName','Helvetica','FontSize',12) hold off; %dot patterns megamatrix mat= m; % the megamatrix dotsize=[100 85 70 55 40 25 10 5 1]; %defines dot sizes dotsize=dotsize/2; %rescale for multiple subplots % get the structure of the matrix mats=zeros(nstates*nstages,nstates*nstages,length(dotsize)); mats(:,:,1) = mat>=1; mats(:,:,2) = (mat>=.75 & mat<1); mats(:,:,3) = (mat>=.50 & mat<.75); mats(:,:,4) = (mat>=.25 & mat<.5); mats(:,:,5) = (mat>=.1 & mat<.25); mats(:,:,6) = (mat>=0.01 & mat<.1); mats(:,:,7) = (mat>=0.001 & mat<.01); mats(:,:,8) = (mat>=0.0001 & mat<.001); mats(:,:,9) = (mat<0.0001 & mat>0); matdiag = eye(nstages); figure for i=1:length(dotsize); %spy(mats(:,:,i),dotsize(i),'k'); %makes the dots black, does not work in %MATLAB 7 spy(mats(:,:,i),dotsize(i)); hold on; end; %spy(matdiag,10,'w+'); %mark the diagonal with white plus text(5,1,['State-stage transitions']); %xvalues=['1';'2';'3';'4';'5';'6';'7';'8']; now defined at outset %set(gca,'XTick',xtick2); %set(gca,'XTickLabel',{xvalues2},'FontName','Helvetica','FontSize',10) %set(gca,'YTick',xtick2); %set(gca,'YTickLabel',{xvalues2},'FontName','Helvetica','FontSize',10) xlabel('State-stage at time {\it t}','FontName','Helvetica','FontSize',12) ylabel('State-stage at time {\it t+1}','FontName','Helvetica','FontSize',12) hold off;