#loads package require(dplyr) require(lme4) require(extrafont) #sets working directory setwd("/Users/ajblake/Documents/Projects/False Black Widows/Manuscripts/Mating of S. grossa/Dryad Data & Scripts") #loads data from file f.wgt.size<-read.csv("female weights and sizes.csv", header=T) #Converts spider ID number from a factor to a character vector f.wgt.size$female.id<-as.character(f.wgt.size$female.id) #loads data from file m.wgt.size<-read.csv("male weights and sizes.csv", header=T) #Converts spider ID number from a factor to a character vector m.wgt.size$male.id<-as.character(m.wgt.size$male.id) #------- Male Weight by Tibia Length Regression ---------- m.wgts.m1<-lmer(log(m_wgt)~m_tib_length+(m_tib_length|group), data=m.wgt.size) summary(m.wgts.m1) #plot showing residuals plot(m.wgt.size$m_tib_length, resid(m.wgts.m1)) #adds residuals as data column to data m.wgt.size$m_wgtres<-resid(m.wgts.m1) #Writes new data with residuals to new file write.csv(m.wgt.size, "male weights and sizes.csv", row.names=F) #------- Female Weight by Tibia Length Regression ---------- f.wgts.m1<-lm(log(f_wgt)~f_tib_length, data=f.wgt.size) summary(f.wgts.m1) #plot showing residuals plot(f.wgt.size$f_tib_length, resid(f.wgts.m1)) #adds residuals as data column to data f.wgt.size$f_wgtres<-resid(f.wgts.m1) #Writes new data with residuals to new file write.csv(f.wgt.size, "female weights and sizes.csv", row.names=F) #------- Weight by Tibia Length Regression Graph ---------- #Set figure width, figure height, and margins #All inputs in inches f_width<-7.5 f_height<-7.7 m_bottom<-0.2 m_left<-1.0 m_top<-0.1 m_right<-0.1 m_inner<-0.6 #colors alpha<-171 col.pal<-c( rgb(197,27,125, alpha=alpha, maxColorValue=255), rgb(77,146,33, alpha=alpha, maxColorValue=255), rgb(127,188,65, alpha=alpha, maxColorValue=255), rgb(184,225,134, alpha=alpha, maxColorValue=255)) pdf("S2 Fig.pdf", width=f_width, height=f_height, family="Arial", pointsize=12) par( mfcol=c(2,1), omi=c(m_bottom, m_left, m_top, m_right), mai=c(m_inner, 0, 0, 0), mgp=c(2.25, 0.7, 0)) #--Male Plot #Axes limits xlim<-c(0,7) ylim<-c(0,0.06) X<-seq(0, 7, 0.05) #Plot Call plot.new() plot.window(xlim=xlim, ylim=ylim) #Points with(m.wgt.size[m.wgt.size$group=="A",], points(m_tib_length, m_wgt, pch=16, col=col.pal[4])) with(m.wgt.size[m.wgt.size$group=="B",], points(m_tib_length, m_wgt, pch=16, col=col.pal[3])) with(m.wgt.size[m.wgt.size$group=="C",], points(m_tib_length, m_wgt, pch=16, col=col.pal[2])) #Model Lines lines(X, exp(predict(m.wgts.m1, data.frame(m_tib_length=X, group="A"))), lty=1, lwd=2, col=col.pal[4]) lines(X, exp(predict(m.wgts.m1, data.frame(m_tib_length=X, group="B"))), lty=1, lwd=2, col=col.pal[3]) lines(X, exp(predict(m.wgts.m1, data.frame(m_tib_length=X, group="C"))), lty=1, lwd=2, col=col.pal[2]) #Subpanel Label text("A♂", x=xlim[1], y=ylim[2], adj=c(0,1), font=2) #Axes axis(1, las=1, lwd=0, lwd.ticks=1, at=axisTicks(xlim,log=F), cex.axis=1) axis(2, las=1, lwd=0, lwd.ticks=1, at=axisTicks(ylim,log=F), cex.axis=1) box(bty="l") #--Female Plot #Axes limits xlim<-c(3,6) ylim<-c(0,0.205) X<-seq(0, 7, 0.05) #Plot Call plot.new() plot.window(xlim=xlim, ylim=ylim) #Points with(f.wgt.size, points(f_tib_length, f_wgt, pch=16, col=col.pal[1])) #Model Lines lines(X, exp(predict(f.wgts.m1, data.frame(f_tib_length=X))), lty=1, lwd=2, col=col.pal[1]) #Subpanel Label text("B♀", x=xlim[1], y=ylim[2], adj=c(0,1), font=2) #Axes axis(1, las=1, lwd=0, lwd.ticks=1, at=axisTicks(xlim,log=F), cex.axis=1) axis(2, las=1, lwd=0, lwd.ticks=1, at=axisTicks(ylim,log=F), cex.axis=1) box(bty="l") #Axes labels (1 line = 0.2 inches) mtext("Tibia-patella length (mm)", side=1, line=-0.8, outer=T) mtext("Body weight (g)", side=2, line=3.4, outer=T) #Close Graph dev dev.off()