# NOTE: the function my.percent() is locally stored on my computer (Hugo) and won't work remotely # source("C:/Users/hdmfla/Google Drive/R/Rfunctions/my.percent.R") # 2020-07-03 HF: Copying the contents of the above-mentioned file here: my.percent <- function(x,precision=1,symbol=TRUE) { if ( length(x) == 0 ) return(character()) x <- round((x*100), precision) if( symbol ){ return(paste0(x, "%")) } else { return(x) } } # end of file. # source("C:/Users/hdmfla/Google Drive/R/Rfunctions/expand.line.R") # 2020-07-03 HF: Copying the contents of the above-mentioned file here: expand.line <- function(x1,x2,y1,height=0,y2=y1){ y3 <- max(c(y1,y2)) + height output <- data.frame(x = c(x1,x1,x2,x2), y = c(y1,y3,y3,y2)) return(output) } # end of file. # source("C:/Users/hdmfla/Google Drive/R/Rblocks/colorblind.R") # 2020-07-03 HF: Copying the contents of the above-mentioned file here: cbPalette <- c("#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00", "#CC79A7", "#999999") names(cbPalette) <- c("Orange","Blue","Green","Yellow","Darkblue","Darkorange","Pink","Grey") cb <- c("#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00", "#CC79A7", "#999999") # end of file. title <- read.csv("Raw_files/new_title_layer.csv") abstract <- read.csv("Raw_files/abstract_layer.csv") fulltext <- read.csv("Raw_files/text_layer.csv") papers <- read.csv("Raw_files/database_rockfish_free.csv") library(scales) library(ggplot2) # Screening results # 1.1) preparing the title layer # title <- read.csv("Raw_files/new_title_layer.csv") # a <- match(title$Title,old.title$Title)[!is.na(match(title$Title,old.title$Title))] # b <- match(order.title$Title,new.title$Title)[!is.na(match(order.title$Title,new.title$Title))] # don't forget to check column consistency # new.title[b,c(9,12:16)] <- order.title[a,c(8:13)] # new.title[decision,c(9,12:16)] <- temp[decision,c(9,12:16)] # [1] "Title" "Author" "Year" "Country" "sco" # [6] "wos" "dtu" "E_title" "M_eco" "M_species" # [11] "M_location" "M_off.topic" "M_other" title.total <- nrow(title) E.title.total <- sum(title$E_title) E.title.eco <- sum(title$M_eco) E.title.species <- sum(title$M_species) E.title.local <- sum(title$M_location) E.title.off <- sum(title$M_off.topic) E.title.other <- sum(title$M_other) # this fragment is used to test relationships between columns #output <- vector() #for( i in 1:nrow(title) ){ # output[i] <- title[i,5] == 1 & title[i,8]== 1 #} #sum(output) ## # dtu # 3761 total # 3446 excluded (91.62) # 2011 off-topic (58.36 of the exclusions) (78.07 of the off-topics) # sco # 1731 total # 1504 excluded (86.89) # title.total # 2333 E.title.total; E.title.total/title.total # 2036 87.27 E.title.eco; E.title.eco/E.title.total # 113 05.55 E.title.species; E.title.species/E.title.total # 715 35.12 E.title.local; E.title.local/E.title.total # 80 03.93 E.title.off; E.title.off/E.title.total # 1100 54.03 E.title.other; E.title.other/E.title.total # 28 01.38 sum(E.title.eco,E.title.species,E.title.local,E.title.off,E.title.other) ## ERROR TESTING # not included but no reason output <- vector() for( i in 1:nrow(title) ){ decision <- title[i,8]==1 & sum(title[i,11:15])==0 if( decision ){ output[i] = 1 } else { output[i] = 0 } } sum(output) # double exclusions output <- vector() for( i in 1:nrow(title) ){ if( sum(title[i,11:15])>1 ){ output[i] = 1 } else { output[i] = 0 } } sum(output) # included but excluded output <- vector() for( i in 1:nrow(title) ){ decision <- title[i,8]==0 & sum(title[i,11:15])>0 if( decision ){ output[i] = 1 } else { output[i] = 0 } } sum(output) ## ## # 2.1) preparing the abstract layer # abstract <- read.csv("Raw_files/abstract_layer.csv") abstract.total <- nrow(abstract) E.abstract.total <- sum(abstract$E_abstract) E.abstract.eco <- sum(abstract$M_eco) E.abstract.species <- sum(abstract$M_species) E.abstract.local <- sum(abstract$M_location) E.abstract.off <- sum(abstract$M_off.topic) E.abstract.other <- sum(abstract$M_other) # this fragment is used to test relationships between columns #output <- vector() #for( i in 1:nrow(abstract) ){ # output[i] <- abstract[i,5] == 1 & abstract[i,8]== 1 #} #sum(output) ## # dtu # 3761 total # 3446 excluded (91.62) # 2011 off-topic (58.36 of the exclusions) (78.07 of the off-topics) # sco # 1731 total # 1504 excluded (86.89) # abstract.total # 297 E.abstract.total; E.abstract.total/abstract.total # 136 45.79 E.abstract.eco; E.abstract.eco/E.abstract.total # 21 15.44 E.abstract.species; E.abstract.species/E.abstract.total # 44 32.35 E.abstract.local; E.abstract.local/E.abstract.total # 20 14.70 E.abstract.off; E.abstract.off/E.abstract.total # 34 25.00 E.abstract.other; E.abstract.other/E.abstract.total # 17 12.50 sum(E.abstract.eco,E.abstract.species,E.abstract.local,E.abstract.off,E.abstract.other) ## ERROR TESTING # not included but no reason output <- vector() for( i in 1:nrow(abstract) ){ decision <- abstract[i,9]==1 & sum(abstract[i,11:15])==0 if( decision ){ output[i] = 1 } else { output[i] = 0 } } sum(output) # double exclusions output <- vector() for( i in 1:nrow(abstract) ){ if( sum(abstract[i,11:15])>1 ){ output[i] = 1 } else { output[i] = 0 } } sum(output) # included but excluded output <- vector() for( i in 1:nrow(abstract) ){ decision <- abstract[i,9]==0 & sum(abstract[i,11:15])>0 if( decision ){ output[i] = 1 } else { output[i] = 0 } } sum(output) ## ## # 3.1) preparing the full text layer # fulltext <- read.csv("Raw_files/text_layer.csv") text.total <- nrow(fulltext) E.text.total <- sum(fulltext$E_text) E.text.eco <- sum(fulltext$M_eco) E.text.species <- sum(fulltext$M_species) E.text.local <- sum(fulltext$M_location) E.text.off <- sum(fulltext$M_off.topic) E.text.other <- sum(fulltext$M_other) # this fragment is used to test relationships between columns #output <- vector() #for( i in 1:nrow(fulltext) ){ # output[i] <- fulltext[i,5] == 1 & fulltext[i,8]== 1 #} #sum(output) ## text.total # 161 E.text.total; E.text.total/text.total # 116 (72%) E.text.eco; E.text.eco/E.text.total # 16 (14%) E.text.species; E.text.species/E.text.total # 24 (21%) E.text.local; E.text.local/E.text.total # 57 (49%) E.text.off; E.text.off/E.text.total # 08 (7%) E.text.other; E.text.other/E.text.total # 11 (9%) sum(E.text.eco,E.text.species,E.text.local,E.text.off,E.text.other) #check ## # ggplot2 plot.values<- c( title.total <- nrow(title) ,E.title.total <- sum(title$E_title) ,E.title.eco <- sum(title$M_eco) ,E.title.species <- sum(title$M_species) ,E.title.local <- sum(title$M_location) ,E.title.off <- sum(title$M_off.topic) ,E.title.other <- sum(title$M_other) # ,abstract.total <- nrow(abstract) ,E.abstract.total <- sum(abstract$E_abstract) ,E.abstract.eco <- sum(abstract$M_eco) ,E.abstract.species <- sum(abstract$M_species) ,E.abstract.local <- sum(abstract$M_location) ,E.abstract.off <- sum(abstract$M_off.topic) ,E.abstract.other <- sum(abstract$M_other) # ,text.total <- nrow(fulltext) ,E.text.total <- sum(fulltext$E_text) ,E.text.eco <- sum(fulltext$M_eco) ,E.text.species <- sum(fulltext$M_species) ,E.text.local <- sum(fulltext$M_location) ,E.text.off <- sum(fulltext$M_off.topic) ,E.text.other <- sum(fulltext$M_other) ) plot.notes <- c( "" ,my.percent(E.title.total/title.total) ,paste(my.percent(E.title.eco/E.title.total),"*",sep="") ,paste(my.percent(E.title.species/E.title.total),"*",sep="") ,paste(my.percent(E.title.local/E.title.total),"*",sep="") ,paste(my.percent(E.title.off/E.title.total),"*",sep="") ,paste(my.percent(E.title.other/E.title.total),"*",sep="") ,"" ,my.percent(E.abstract.total/abstract.total) ,paste(my.percent(E.abstract.eco/E.abstract.total),"*",sep="") ,paste(my.percent(E.abstract.species/E.abstract.total),"*",sep="") ,paste(my.percent(E.abstract.local/E.abstract.total),"*",sep="") ,paste(my.percent(E.abstract.off/E.abstract.total),"*",sep="") ,paste(my.percent(E.abstract.other/E.abstract.total),"*",sep="") ,"" ,my.percent(E.text.total/text.total) ,paste(my.percent(E.text.eco/E.text.total),"*",sep="") ,paste(my.percent(E.text.species/E.text.total),"*",sep="") ,paste(my.percent(E.text.local/E.text.total),"*",sep="") ,paste(my.percent(E.text.off/E.text.total),"*",sep="") ,paste(my.percent(E.text.other/E.text.total),"*",sep="") ) plot.x <- rep(c("Total" ,"Excluded" ,"Ecosystem" ,"Species" ,"Location" ,"Off-topic" ,"Other" ), 3 ) PlotData <- data.frame(Value=plot.values ,Labels=factor(plot.x,levels=c("Total","Excluded","Ecosystem","Species","Location","Off-topic","Other")) ,Color=rep(c(rep(cbPalette[[2]],2),rep(cbPalette[[3]],5)),3) ,Note=plot.notes,Note.x=rep(c(1:7),3),Note.y=c(plot.values[1:7]+90,plot.values[8:14]+10,plot.values[15:21]+5) ,Level=factor(rep(c("a) Title","b) Abstract","c) Full text"),each=7),levels=c("a) Title","b) Abstract","c) Full text")) ) p <- ggplot(PlotData,aes(y=Value, x=Labels)) p <- p + geom_bar(stat="identity", fill=PlotData$Color) p <- p + geom_text(aes(x=Note.x,y=Note.y,label=Note),size=2) p <- p + facet_wrap(.~Level, scales="free_y") p <- p + theme_bw() p <- p + theme(axis.text.x = element_text(angle = 45, hjust = 1.1)) p <- p + scale_y_continuous(expand = c(0.0, 0.00)) p <- p + labs(x="", y="Number of papers") p <- p + theme(panel.grid.minor.x = element_blank() ,panel.grid.major.x = element_blank() ) p ggsave("exclusion_process.eps",width=8,height=3) ggsave("exclusion_process.png",width=8,height=3) rm(list=ls()[grep("E.",ls())]) rm(abstract.total,plot.labels,plot.notes,plot.values,plot.x,text.total,title.total) #................... # Analyses papers <- read.csv("Raw_files/database_rockfish_free.csv") # -- # recipient <- vector() # for(i in 58:128){ # recipient[length(recipient)+1] <- sum(papers[,i]) # } # names(recipient) <- colnames(papers)[58:128] # to.plot <- recipient[rev(order(recipient))] # png("Figures/per.species.png",height=400, width=400, unit="px", bg="transparent") # par(mar=c(4,4,1,1) # ,las=2 # ) # barplot(to.plot[1:10] # ,ylab="Nº of accepted papers" # ,col="royalblue" # ) # dev.off() # -- recipient <- vector() for(i in c(39:51) ){ recipient[length(recipient)+1] <- sum(papers[,i]) } labels <- c("Biomass", "Density", "Biodiversity", "Condition", "Mortality", "Growth", "Feeding", "Spawning", "Nursery", "Settling", "Diel cycle", "Site fidelity", "Migration") my.colors <- c(rep(cbPalette[1],3) ,rep(cbPalette[2],4) ,rep(cbPalette[3],3) ,rep(cbPalette[4],3)) PlotData <- data.frame(Values=recipient ,x=labels,Groups=c(rep("Community-related",3),rep("Fitness-related",4),rep("Reproduction-related",3),rep("Distribution-related",3)) ) PlotData$x <- with(PlotData, factor(x,levels=x[rev(order(recipient))])) p <- ggplot(PlotData,aes(x=x,y=Values,fill=Groups)) p <- p + geom_bar(stat="identity") p <- p + theme_bw() p <- p + theme(axis.text.x = element_text(angle = 45, hjust = 1.1)) p <- p + scale_y_continuous(limits=c(0,26), expand = c(0.0, 0.00)) p <- p + labs(x="", y="Number of papers") p <- p + theme(panel.grid.minor.x = element_blank() ,panel.grid.major.x = element_blank() ,legend.title = element_blank() ,legend.position = c(.98, .98) ,legend.justification = c("right", "top") ,legend.box.just = "right" ,legend.margin = margin(2, 6, 2, 2) # top, left, down, right ,legend.background = element_rect(fill="white",linetype="solid", colour ="black", size=0.35) ) p <- p + scale_fill_manual(values = c("Community-related"=cbPalette[[1]] ,"Fitness-related"=cbPalette[[2]] ,"Reproduction-related"=cbPalette[[3]] ,"Distribution-related"=cbPalette[[4]] )) p ggsave("per_variable.png",width=4,height=3) ggsave("per_variable.pdf",width=4,height=3) #png("Figures/per.variable.png",height=300, width=400, unit="px", bg="white") # postscript("Figures/per_variable_updated.eps",height=3.5, width=5.5, bg="transparent", horizontal=F) # par(mar=c(4.5,4,1,0) # ,las=2 # ) # xx <- barplot(to.plot # ,axes = FALSE # ,axisnames = FALSE # ,ylab="Nº of reviewed papers" # ,col=my.colors[rev(order(recipient))] # ,ylim=c(0,30) # ) # text(xx # ,par("usr")[3] # ,labels = labels[rev(order(recipient))] # ,srt = 45 # ,adj = c(1.1,1.1) # ,xpd = TRUE # # ,cex = 0.8 # ) # axis(2 # ,las=2 # # ,cex.axis=0.8 # ) # legend(xx[7],30 # ,c("Community-related","Fitness-related","Reproduction-related","Distribution-related") # ,fill=unique(my.colors) # ) # dev.off() # -- #pre-tables my.list <- list(papers[papers$GadMor ==1,] ,papers[papers$CluHar ==1,] ,papers[papers$PolVir ==1,] ,papers[papers$MulSur ==1,] ,papers[papers$MerMer ==1,] ,papers[papers$PolPol ==1,] ,papers[papers$PlePla ==1,] ,papers[papers$SolSol ==1,] ) names(my.list) <- c("GadMor","CluHar","PolVir","MulSur","MerMer","PolPol","PlePla","SolSol") # Substrate table recipient <- matrix(nrow=9,ncol=9) the.column <- c("H_Natural","H_Artificial","H_intentional","H_colateral","H_platform","H_wind","H_shipwreck") for( i in 1:8 ){ divider <- nrow(my.list[[i]]) for( k in 1:7 ){ a <- sum(my.list[[i]][,the.column[k]]) recipient[k,i] <- paste(a,"(",my.percent(a/divider,symbol=F),")",sep="") } other <- sum(my.list[[i]][,"H_seawall"],my.list[[i]][,"H_riprap"],my.list[[i]][,"H_other"]!=0) recipient[8,i] <- paste(other,"(",my.percent(other/divider,symbol=F),")",sep="") recipient[9,i] <- paste(divider,"(",my.percent(divider/nrow(papers),symbol=F),")",sep="") } for( k in 1:7 ){ recipient[k,9] <- paste(sum(papers[,the.column[k]]),"(",my.percent(sum(papers[,the.column[k]])/nrow(papers),symbol=F),")",sep="") } recipient[8,9] <- paste(sum(papers$H_seawall,papers$H_riprap,papers$H_other!=0),"(",my.percent(sum(papers$H_seawall,papers$H_riprap,papers$H_other!=0)/nrow(papers),symbol=F),")",sep="") recipient[9,9] <- nrow(papers) to.add <- c("1) Nat. Reefs","2) Art. Reefs","2.1) Intentional","2.2) De facto","2.2.a) Platforms","2.2.b) Wind Farms","2.2.c) Shipwrecks","2.2.d) Other","Total") to.print <- cbind(to.add,as.data.frame(recipient)) colnames(to.print) <- c("NA",names(my.list),"Total") print( xtable::xtable(to.print,digits=0), include.rownames=F, include.colnames=T, hline.after = NULL, floating=F, only.contents=T, print.results=T ) # Variable table recipient <- matrix(nrow=14,ncol=9) the.column <- colnames(papers[,39:51]) for( i in 1:8 ){ divider <- nrow(my.list[[i]]) for( k in 1:13 ){ a <- sum(my.list[[i]][,the.column[k]]) recipient[k,i] <- paste(a,"(",my.percent(a/divider,symbol=F),")",sep="") } recipient[14,i] <- paste(divider,"(",my.percent(divider/nrow(papers),symbol=F),")",sep="") } for( k in 1:13 ){ recipient[k,9] <- paste(sum(papers[,the.column[k]]),"(",my.percent(sum(papers[,the.column[k]])/nrow(papers),symbol=F),")",sep="") } recipient[14,9] <- nrow(papers) to.add <- c("Biomass", "Density", "Biodiversity", "Condition", "Mortality", "Growth", "Feeding", "Spawning", "Nursery", "Settling", "Diel cycle", "Site fidelity", "Migration", "Total") to.print <- cbind(to.add,as.data.frame(recipient)) colnames(to.print) <- c("NA", names(my.list),"Total") print( xtable::xtable(to.print,digits=0), include.rownames=F, include.colnames=T, hline.after = NULL, floating=F, only.contents=T, print.results=T ) # new barplot # to.plot <- with(papers,c(sum(H_Natural) # ,sum(H_Artificial) # ,NA # ,sum(H_intentional) # ,sum(H_colateral) # ,NA # ,sum(H_wind) # ,sum(H_shipwreck) # ,sum(H_platform) # ,4 # 3 Others + 1 riprap # )) # # apply(papers[,30:37],2,sum) # # sum(papers[,38]!=0) # labels <- c("Natural","Artificial","" # ,"Intentional","De facto","" # ,"Wind farms","Shipwrecks","Oil platforms","Other") # colors <- c(rep("lightblue",2) # ,NA # ,rep("olivedrab1",2) # ,NA # ,rep("lightgreen",4) # ) # postscript("Figures/per_substrate_updated.eps",height=3.5, width=5.5, bg="transparent", horizontal=F) # par(mar=c(5,4,1,0)) #bottom, left, top and right # xx <- barplot(to.plot # ,axes = FALSE # ,axisnames = FALSE # ,ylab="Number of Papers" # ,ylim = c(0,30) # ,col = colors # ) # text(xx # ,par("usr")[3] # ,labels = labels # ,srt = 45 # ,adj = c(1.1,1.1) # ,xpd = TRUE # # ,cex = 0.8 # ) # axis(2 # ,las=2 # # ,cex.axis=0.8 # ) # ## Add text at top of bars # text(x = xx # ,y = to.plot # ,label = my.percent(to.plot/45) # ,pos = 3 # # ,cex = 0.7 # ) # h1 <- max(to.plot[1:2]) # h2 <- max(to.plot[4:5]) # lines(x=c(xx[4]-.5,xx[5]+0.5),y=rep(h1,2),lty=1) # lines(x=rep(xx[5]+0.5,2),y=c(h1,h1-2),lty=1) # lines(x=rep(xx[4]-0.5,2),y=c(h1,h1-2),lty=1) # lines(x=c(xx[7]-.5,xx[10]+0.5),y=rep(h2,2),lty=1) # lines(x=rep(xx[10]+0.5,2),y=c(h2,h2-2),lty=1) # lines(x=rep(xx[7]-0.5,2),y=c(h2,h2-2),lty=1) # rm(h1,h2) # text(x = c(xx[4]+0.6, xx[8]+0.6) # ,y = to.plot[c(2,5)] # ,label = c("Artificial","De facto") # ,pos = 3 # # ,cex = 1 # ,font = c(1,3) # ) # dev.off() PlotData <- data.frame( Values=with(papers,c(sum(H_Natural) ,sum(H_Artificial) ,0 ,sum(H_intentional) ,sum(H_colateral) ,0 ,sum(H_wind) ,sum(H_shipwreck) ,sum(H_platform) ,4 # 3 Others + 1 riprap )) ,x=letters[1:10] ,x.labels=c("Natural","Artificial","" ,"Intentional","De facto","" ,"Wind farms","Shipwrecks","Oil platforms","Other") ,Colors=c(rep(cbPalette[[1]],2) ,NA ,rep(cbPalette[[2]],2) ,NA ,rep(cbPalette[[3]],4) ) ) PlotData$Note <- my.percent(PlotData$Values/45) PlotData$Note[c(3,6)] <- "" p <- ggplot(PlotData,aes(x=x,y=Values)) p <- p + geom_bar(stat="identity", fill=PlotData$Colors) p <- p + scale_y_continuous(limits=c(0,30), expand = c(0.0, 0.00)) p <- p + scale_x_discrete(breaks=letters[c(1,2,4,5,7:10)],labels=PlotData$x.labels[c(-3,-6)]) p <- p + theme_bw() p <- p + theme(axis.text.x = element_text(angle = 45, hjust = 1.1)) p <- p + labs(x="", y="Number of papers") p <- p + geom_line(data=expand.line(3.5,5.5,21,height=0.5),aes(x=x,y=y)) p <- p + geom_line(data=expand.line(6.5,10.5,14,height=0.5),aes(x=x,y=y)) p <- p + geom_text(x=4.5,y=22.5,label="Artificial",size=2) p <- p + geom_text(x=8.5,y=15.5,label="de facto",fontface = "italic",size=2) p <- p + geom_text(aes(x=x,y=Values+1,label=Note),size=2) p <- p + theme(panel.grid.minor.x = element_blank() ,panel.grid.major.x = element_blank() ) p ggsave("per_substrate.png",width=4,height=3) ggsave("per_substrate.pdf",width=4,height=3) t(t(colnames(papers))) sum(apply(papers[,39:41],1,sum)>0)/nrow(papers) # 2019-07-21 comment by Dave and Josianne # Dave: I think that, in general, the Results do not spend enough time describing # interesting results for each ofthe 4 categories of consideration. For example, # add interesting and specific examples of how the various components of a given # category (e.g., examples within specieis distribitions, or community, etc.) vary # between hardbottom versus other habitats, or within hardbottoms for different species. # # Josianne: Hugo, from your xcel file can you find if thefish community is # similar/different in the different catagoreis in figure 4 below. this could be added # to the text to provide more information for results to respond to DAve's comment 17. # # bergstrom2013 A N # eel 1 1 # cod 1 1 # cod 1 1 # whiting 1 0 # Pflesus 1 1 # Pplatessa 1 1 # Sole 1 1 # bertoncini2010 no significant differences between AR and natural R # borges2007 - natural only # AmmSpp # CapApe # EngEnc # MulSur # SarPil # TraTra # castege2016 - artificial only # DicLab # EngEnc # MalVil # MulSur # PolPol # SarPil # ScoRho # SolSol # TraTra # Fujii2015 - artificial only # BroBro # GadMor # MelAeg # PolVir # griffin2016 - artificial only # MerMer # ScyCan # ScySte # SolSol # henriques2013 - Natural only # DicLab # MulSur # PagBog # PolPol # hunter2009 # GadMor non significant differences # PolPol non significant differences # PolVir not present in the table