# Foodweb R code parasitoid<-c("Bracon1", "Bracon1", "Bracon1","Bracon1", "Bracon1", "agathidine1", "agathidine1", "agathidine1","agathidine1", "Cotesia1", "Cotesia1", "Cotesia1", "Cotesia1", "Cotesia2", "Cotesia3", "Cotesia3", "Cotesia3", "Cotesia4", "Aleiodes1", "Aleiodes2", "Macrocentrus1") host<-c("Nymphalidae2", "Erebidae1", "Erebidae1", "Erebidae1", "Erebidae1", "Erebidae2", "Erebidae2", "Noctuid1", "Lycaenidae1", "Hesperidae1", "Hesperidae1", "Hesperidae1", "Hesperidae2", "Noctuidae2", "Geometridae1", "Geometridae2", "Erebidae1", "Erebidae1", "Erebidae1", "Erebidae3", "Erebidae4") l<-levels(as.factor(parasitoid)) m<-levels(as.factor(host)) plot(NULL, axes=F,xlab="",ylab="",xlim=c(0,length(parasitoid)),ylim=c(0,5)) P<-NULL H<-NULL for(i in 1:length(l)) P<-c(P,length(which(parasitoid==l[i]))) for(i in 1:length(m)) H<-c(H,length(which(host==m[i]))) S<-cumsum(P) S1<-c(0,S) T<-cumsum(H) T1<-c(0,T) for(i in 1:length(l)) rect(S1[i],3.9,S1[i+1],5.7,col="red",lwd=6,border="white") for(j in 1:length(m)) rect(T1[j],0.7,T1[j+1],2,col="green",lwd=6,border="white") midT<-T1[1:length(T)]+(T-T1[1:length(T)])/2 midS<-S1[1:length(S)]+(S-S1[1:length(S)])/2 for(i in 1:length(l)) text(midS[i],4.1,l[i],srt=90,cex=0.8,xpd=NA,adj=0,font=3) for(i in 1:length(m)) text(midT[i],1.9,m[i],srt=270,cex=0.8,xpd=NA,adj=0,font=3) for(k in 1:length(l)){ pp<-which(parasitoid==l[k]) np<-length(pp) hostsofparasitoid<-host[pp]#### links<-length(levels(as.factor(hostsofparasitoid))) for(q in 1:links){ noRearings<-length(which(hostsofparasitoid==levels(as.factor(hostsofparasitoid))[q])) temph<-which(m==levels(as.factor(hostsofparasitoid))[q]) lines(c(midS[k],midT[temph]),c(3.8,2.2),col="grey50",lwd=noRearings*2,lend=3) } } points(midT,rep(2.2,length(T)),pch=15,col="blue") #putting the squares at the end of the connecting lines points(midS,rep(3.8,length(S)),pch=15,col="blue")