Appendix 1: R script detailing the approach used in this study. # Simplified version of the script used in this study. Provide an overview of the general method employed. #------------------------------------------------------------------------ # create and plot background matrix with artificial barrier in middle m <- matrix(1, nrow=10, ncol=10) ; m m[,5] <- 4 library(raster) r <- raster(m) plot(r) # create and plot transition matrix library(gdistance) t <- transition(r, transitionFunction=mean, 4, symm=TRUE, intervalBreaks=3) plot(raster(t)) # create and plot sampling points and genetic data associated. # (x coordinates, y coordinates, genetic data for 3 loci) matG2 <- matrix(c(0.21, 0.22, 0.82, 0.23, 0.81, 0.83, 0.81, 0.21, 0.50, 0.51, 0.23, 0.83, 0, 0, 2, 0, 1, 1, 1, 2, 1, 1, 1, 0, 2, 1, 0, 1, 0, 0), ncol=5) xcoord<- matG2[, 1] ; ycoord <- matG2[, 2] P<-cbind(xcoord,ycoord) points(P) # construction of moving windows (sampling areas) library("ade4") ; library("vegan") # Define the extent of sampling areas and the interval wanted Min <- 0.7 # Minimum radius of areas wanted Max <- 0.9 # Maximum radius of areas wanted Step <- 0.1 # interval wanted # Loops to test correlations in sampling area at multiple scales and locations resultsfinal <- cbind(1,1,1,1,1) colnames(resultsfinal) <- c("xcoord","Ycoord", "Radius", "MantelR", "Pval") for(Radius in seq(Min, Max, by = Step)){ results = NULL for(i in 1:length(xcoord)){ Xcircle <- ( xcoord [i] + Radius*cos(seq(0,2*pi,length.out=100))) Ycircle <- ( ycoord [i] + Radius*sin(seq(0,2*pi,length.out=100))) polygon(Xcircle, Ycircle) # extract individuals data in each sampling are constructed expr <- point.in.polygon(xcoord,ycoord,Xcircle,Ycircle) xcoord[expr==1] ycoord[expr==1] coordPoly <- cbind (xcoord[expr==1],ycoord[expr==1]) # sort data and compute matrix of basic pairwise euclidian distances (not used further in this example) CoordOrder<- coordPoly[order(coordPoly[,1],decreasing=FALSE),] locOrder<-data.frame(CoordOrder) DisGeoEucl<-dist(locOrder, method = "euclidean", diag = TRUE, upper = TRUE) # compute corresponding matrix of genetic distances listcoord = (1:6)[expr==1] Genet = NULL ## fichier vide pour collage des données for(h in listcoord){ tmp <- matG2[(matG2[, 1]==xcoord[h])and(matG2 [, 2]== ycoord[h]), ] Genet = rbind(Genet,tmp) } GenetOrder<- Genet[order(Genet[,1],decreasing=FALSE),] GenetOrderSanscoord <- GenetOrder[,-c(1,2)] MatdistGenet<- vegdist(GenetOrderSanscoord, method="bray", binary=FALSE, diag=FALSE, upper=TRUE, na.rm = TRUE) MatdistGenet <- as.dist(MatdistGenet) # Compute matrix landscape "resistance" distances based on raster spatiallocX <- locOrder[,1] ## extraction des colonnes pour repasser en spatial spatiallocY <- locOrder[,2] SpaLoc <- SpatialPoints(cbind(spatiallocX, spatiallocY)) Resdis<- commuteDistance(t, SpaLoc) Resdis<-as.dist(Resdis, diag = TRUE, upper=TRUE) # simple mantels test between genetic and landscape "resistance" distances MantelpRes <- mantel.rtest(MatdistGenet, Resdis, nrepet = 99) results <- rbind (results, cbind (xcoord [i], ycoord [i],Radius, MantelpRes[2], MantelpRes[4])) } resultsfinal <- rbind(resultsfinal,results) } # display result file with for each individual: x and y coordinates, radius of sampling area, mantel output and associated p-value Resultsfinal