Supplemental file S3 – R code data1<-read.table(file="C:\\Users\\paolucci\\Google Drive\\Articoli\\Diapause\\Diap_tot.txt", header=TRUE) dat<-subset(data1,Sub.Clade!="Corsica") str(dat) summary(dat) names(dat) library(ggplot2) require(methods) library(index) library(car) library(predictmeans) library(nlme) ###Diapause model dat29<-dat[-29,] ##remove very influential point from the dataset based on Cook's distance modd<-lme(Diapause ~ Tmean_n +I(Tmean_n^2)+I(Tmean_n^3), random=~1|Sub.Clade/Site, data=dat29,na.action=na.omit, method="REML") summary(modd) cooks.distance(modd) ###mortality modm<-lme(Mortality~ Diapause, random=~1|Sub.Clade/Site, data=dat,na.action=na.omit, method="REML") summary(modm) ################# Script to produce the figures ## plot base + points dat29<-dat[-29,] pd <- ggplot(dat29, aes(x = Tmean_n, y = Diapause)) + geom_point() print(pd) fig2a<-pd + geom_point(aes(colour = factor(Sub.Clade)), size = 3)+ stat_smooth(method = "lm", formula = y ~ x + I(x^2)+I(x^3), size = 1,se = FALSE) + scale_x_continuous(name="Mean temperature (°C)", limits=c(-2, 13)) + scale_y_continuous(name="Individuals in prolonged diapause (%)", limits=c(0, 100))+ theme_bw() pm <- ggplot(dat, aes(x = Diapause, y = Mortality)) + geom_point() print(pm) fig2b<-pm + geom_point(aes(colour = factor(Sub.Clade)), size = 3)+ stat_smooth(method = "lm", formula = y ~ x , size = 1,se = FALSE) + scale_x_continuous(name="Individuals in prolonged diapause (%)", limits=c(0, 100)) + scale_y_continuous(name="Mortality (%)", limits=c(0, 100))+ theme_bw() # Multiple plot function # Multiple plot function # # ggplot objects can be passed in ..., or to plotlist (as a list of ggplot objects) # - cols: Number of columns in layout # - layout: A matrix specifying the layout. If present, 'cols' is ignored. # # If the layout is something like matrix(c(1,2,3,3), nrow=2, byrow=TRUE), # then plot 1 will go in the upper left, 2 will go in the upper right, and # 3 will go all the way across the bottom. # multiplot <- function(..., plotlist=NULL, file, cols=1, layout=NULL) { library(grid) # Make a list from the ... arguments and plotlist plots <- c(list(...), plotlist) numPlots = length(plots) # If layout is NULL, then use 'cols' to determine layout if (is.null(layout)) { # Make the panel # ncol: Number of columns of plots # nrow: Number of rows needed, calculated from # of cols layout <- matrix(seq(1, cols * ceiling(numPlots/cols)), ncol = cols, nrow = ceiling(numPlots/cols)) } if (numPlots==1) { print(plots[[1]]) } else { # Set up the page grid.newpage() pushViewport(viewport(layout = grid.layout(nrow(layout), ncol(layout)))) # Make each plot, in the correct location for (i in 1:numPlots) { # Get the i,j matrix positions of the regions that contain this subplot matchidx <- as.data.frame(which(layout == i, arr.ind = TRUE)) print(plots[[i]], vp = viewport(layout.pos.row = matchidx$row, layout.pos.col = matchidx$col)) } } } multiplot(fig2a,fig2b, cols=2)