######################################################################################## #Here, we show the R script to compute the Overlapping Area test using the data of #a fully-mapped cryophilic grassland in Sierra de Guadarrama National Park (Spain), #where the crown of each individual plant (i.e. their canopy) for a total of 11 species was #approximated by a polygon. #-------------------------------------------------------------------------------------- #The summary statistic employed in the test (i.e. result5) is the overall sum of the #overlapping areas of intersecting polygons between each species pair. #The observed overlapping area (i.e., the real overlapping area) is the first value #in the vector, and the subsequent ones (i.e. 9999) are the overlapping areas of randomly simulated #spatial configurations ########################################################################################## ##We load the overlapptest package. #Logically, you should have installed the overlapptest package previously! previously! library(overlapptest) #We create a vector with the order of the species present in the plot and other with its names. orden<-c(1:4,6:8,5,9:11) nombres_owins3<-c("AD", "AC", "EP", "FC", "PV", "JC", "JH", "MR", "SB", "SC", "SiC") #We computed p-values of the test for overlapping between pairs of species using the function p-val(). #Function p-val() computes by default a two-sided test. tabla.p2 <- apply(result5,c(1,2), function(x){ if(sum(x,na.rm=TRUE)>0) return (overlapptest::pval(x)) else return(NA)}) # We define the column and row names (i.e. species names) using the name vector. dimnames(tabla.p2)<-list(nombres_owins3, nombres_owins3) # We sort the tables acoording the orden defined previously. tabla.p2_ord <- tabla.p2[orden, orden] # We apply a correction by multiple test: P-adjust by False DIscovery Rate. tabla.p2.adj<-apply(abs(tabla.p2_ord),2,p.adjust, method="fdr")*sign(tabla.p2_ord) round(tabla.p2.adj,4) #We create a funtion to display the p-values using a colour pattern: #White for no significative p-values #Red for "negative p-value": indicates that the observed overlapping area is smaller than expected by the null model of random rotation. #Green for "negative p-value": indicates that the observed overlapping area is higher than expected by the null model of random rotation. #Grey represent those cases where the shape of accessory species never overlaps with the correspondent focal species after to apply random rotation null model. tablea2<- function(d2,fs=8){ require(gridExtra) require(grid) selection<- (as.vector(abs(d2)<=0.05& d2>0)*1)+(as.vector(abs(d2)<=0.05& d2<0)*2)+1 selection[is.na(selection)]<-4 tRWG<- ttheme_default(base_size = fs,core=list( fg_params=list(fontface=c("plain", "italic","bold.italic","plain")[selection]), bg_params = list(fill=c( "white","green","red", "grey")[selection]) )) grid.table(d2, theme = tRWG) } #We display the p-value table. library(gridExtra) dev.new(title="P_VAL_ADJ") tablea2(round(tabla.p2.adj, 4), fs=8)