######### a call to dlogistic will ######### generate a cobweb plot of discrete logistic growth, ######### x[t+1] = r*x[t]*(1-x[t]) ######### for n steps starting from x[0] = x0 # By R. Gomulkiewicz (23 Sep 2013) # modified from cobweb plot on http://bayesianbiologist.com/ dlogistic<- function(r = 1, x0 = runif(1,0,1), n = 100,...) #default values: r = 1, x0 = random uniform between 0 & 1, 100 steps { dlog<- function(r, x){r*x*(1-x)} #the discrete logistic map x<-seq(from=0,to=1,length.out=100) plot(x,dlog(r,x),type='l',xlab=expression(x[t]),ylab=expression(x[t+1]), ylim=c(0,1),main= substitute(paste(italic(r)," = ",x,sep=""),list(x=r))) abline(a=0,b=1) start = x0 end = dlog(r, start) points(start,start, pch = 19) #show the initial point lines(x=c(start,start),y=c(start,end) ) #first draw line from (x0, x0) to (x0, f(x0) vert=FALSE #2nd line will be horizonatal from (x0,f(x0) to (f(x0),f(x0)) for(i in 1:(2*n)) { if(vert) #draw vertical line from (x,x) to (x,f(x)) { lines(x=c(start,start),y=c(start,end) ) vert=FALSE } else #draw horizontal line from (x,f(x)) to (f(x),f(x)) { lines(x=c(start,end),y=c(end,end) ) vert=TRUE start=dlog(r,start) end <- dlog(r, start) } } } ###Call the cobweb plot function with values r = 2.5, 3.5, and 4 dlogistic(r = 2, x0 = 0.1) quartz() dlogistic(r = 3, x0 = 0.1) quartz() dlogistic(r = 4, x0 = 0.1)