#This function plots dynamics and lines using Levins's equation together metapop_plot = function(imi,ext,ini,alfa,dim,nostep, animation) { # imi - immigration rate # ext - extinction rate # ini - proportion of habitats initially occupied (0 - one individual in the centre) # alfa - shape constant for the rescue effect (if == 0 -> standard Levins's equation) # dim - number of rows of cells (dim^2 is the number of habitats) # nostep - number of simulation steps #animation - whether to animate x=seq(0,1,by=0.01); plot(x,imi*x*(1-x),lwd=2,type="l",col="blue",xlab="Proportion of habitats occupied", ylab="Immigration or extinction per step"); lines(x,(ext*x)/(1+alfa*ext*x),lwd=2,col="green"); stp = max(imi*x*(1-x))/10 y=metapop(imi,ext,ini,alfa,dim,0, 0,nostep); xx = seq(stp,stp+(nostep-1)*stp/(nostep),by=stp/(nostep)); if (animation > 0) { for (i in 1:(nostep-1)) { points(y[i],xx[i],col="red",pch=20,type="p"); Sys.sleep(0.2); } } else points(y,xx,col="red",pch=20,type="p"); }