######################################################## # FILENAME: "hump.results.R" # AUTHOR: Dan McGlinn # EMAIL: danmcglinn@gmail.com # DATE CREATED: 11.15.2009 # LAST MODIFIED: 12.30.2009 # PURPOSE: To create an output file from the simulation model # and to examine it graphically ######################################################## ######################################################## ##set the working directory (i.e, location of the file 'hump.sim.R') setwd(".../hump simualtion") ##parameterization as listed in Table 1. ##set inital diameter size diams = .05 ##set number of species in species pool numsp = 100 ##set maximum amount of time to run simulation for Tim = 50 ##set the growth increment diamch = 0.01 ##set the inital number of individuals ns<-c(5,7,9,11,13,15)^2 ##import all the functions in the file 'hump.sim.R' source('hump.sim.R') ##alternatively this can be done by copying and pasting all of the code in this file into the R console ##if using many permuations then it may be necessary to increase ##the memory limit that is typically reserved for a 32-bit R install memory.limit(size=4095) system.time(output<-hump.sim(200,diams,ns,RAD='even',space=c('clustered','random','uniform'),intensity=.95)) ##takes approximatly 1 hour on a 64 bit machine,w/Intel core i7cpu 940@2.93 GHz ##with 8 GB of RAM on R 2.9.2 ##may wish to save the output file now that it is generated ##save.image("simoutput.RData") ##generate graphical output observed in manuscript ##FIGURE 1 - top-down view of simulated communities install.packages('dichromat') ##this package is necessary to use the color scheme called below library(dichromat) cls<- colorRampPalette(colorschemes$Categorical.12)(numsp) axisfnt<-1.25 par(mfrow=c(3,3)) tims<-c(1,15,30) iperm<-4 ##chose a permuation to examine ##place the names of the spatial distributions considered,this will be used for the main title of the graphic spaces<-c('Clustered','Random','Uniform') mult.diam<-50*par()$cex ##necessary to scale point size ##plot the points for(t in 1:length(tims)){ for(s in 1:3){ par(mar=c(2.5,2.5,2.5,2.5)) ifelse(t==1,main<-paste(spaces[s]),main<-'') plot(output[iperm,s,1,length(ns),tims[t],1:ns[length(ns)],1:2],main=main,xlab='',ylab='',xlim=c(0,1),ylim=c(0,1),col=cls[output[iperm,s,1,length(ns),tims[t],1:ns[length(ns)],3]],pch=19,cex=mult.diam*output[iperm,s,1,length(ns),tims[t],1:ns[length(ns)],4],axes=F,frame.plot=T,lwd=2) axis(side=1,at=c(0,.5,1),cex.axis=axisfnt) axis(side=2,at=c(0,.5,1),cex.axis=axisfnt) }} ######################################################## ##FIGURE 2 - Three bivariate relationships generated by the simulation model greens<-c('#99CC99','#669966') blues<-c('#336699','#99CCFF') purples<-c('#660066','#996699') par(mfrow=c(3,3)) lwd<-2 pchs<-1 ## number of individuas vs time time.plot(output,type='l',avg=T,ci=T,poly=T,cls=c(purples[1],NA,NA),cls.poly=c(purples[2],NA,NA),lwd=lwd,pch=pchs,main='Clustered') time.plot(output,type='l',avg=T,ci=T,poly=T,cls=c(NA,blues[1],NA),cls.poly=c(NA,blues[2],NA),lwd=lwd,pch=pchs,main='Random') time.plot(output,type='l',avg=T,ci=T,poly=T,cls=c(NA,NA,greens[2]),cls.poly=c(NA,NA,greens[1]),lwd=lwd,pch=pchs,main='Uniform') ## number of species vs number of individuals raref.plot(output,type='l',avg=T,ci=T,poly=T,cls=c(purples[1],NA,NA),cls.poly=c(purples[2],NA,NA),lwd=lwd,pch=pchs) raref.plot(output,type='l',avg=T,ci=T,poly=T,cls=c(NA,blues[1],NA),cls.poly=c(NA,blues[2],NA),lwd=lwd,pch=pchs) raref.plot(output,type='l',avg=T,ci=T,poly=T,cls=c(NA,NA,greens[2]),cls.poly=c(NA,NA,greens[1]),lwd=lwd,pch=pchs) ## number of species vs total biomass hump.plot(output,type='l',avg=T,ci=T,poly=T,cls=c(purples[1],NA,NA),cls.poly=c(purples[2],NA,NA),lwd=lwd,pch=pchs) hump.plot(output,type='l',avg=T,ci=T,poly=T,cls=c(NA,blues[1],NA),cls.poly=c(NA,blues[2],NA),lwd=lwd,pch=pchs) hump.plot(output,type='l',avg=T,ci=T,poly=T,cls=c(NA,NA,greens[2]),cls.poly=c(NA,NA,greens[1]),lwd=lwd,pch=pchs) ######################################################## ##FIGURE 3 - Unaveraged results par(mfrow=c(1,3)) lwd<-1 pchs<-1 #par(cex=par()$cex*.5) #par(cex.axis=1/.5) cls<-c(purples[2],blues[2],greens[1]) hump.plot(output,type='p',avg=F,cls=c(cls[1],NA,NA),lwd=lwd,pch=pchs,main='Clustered') hump.plot(output,type='p',avg=F,cls=c(NA,cls[2],NA),lwd=lwd,pch=pchs,main='Random') hump.plot(output,type='p',avg=F,cls=c(NA,NA,cls[3]),lwd=lwd,pch=pchs,main='Uniform')