# ABUNDANCE DATA ---- library(reshape2) library(ggplot2) CV <- read.csv("database.csv") ## Database with abundance of organisms, depth and reef zones only str(CV) MRZ <- CV[c(1,3:7)] # Get only Reef zones and abundance of organisms MDZ <- CV[c(2:7)] # Get only Depth zones (scaled in the desired categories) and organisms # Change name of variable ---- colnames(MRZ)[which(names(MRZ) == "Hard.Corals")] <- "Hard Corals" str(MRZ) # Boxplot Organisms abundance by Reef Zones---- data <- melt(MRZ, id.var = "Reef.Zone") ## Melt variables with reef zone reefzones <- ggplot(data = data, aes(x=Zone, y=value)) + geom_boxplot(aes(fill=variable))+ ylim(0, 100)+ scale_x_discrete(limits=c('Windward','Crest','Leeward'))+ xlab("Reef Zone") + ylab("Percent Cover") + guides(fill=guide_legend(title="Organisms"))+ theme( legend.title=element_blank(), axis.text.x = element_text(colour="153", size=12), axis.text.y = element_text(colour="153", size=12), panel.background = element_rect(fill="white"), panel.grid.minor=element_blank(), panel.grid.major=element_blank(), legend.text = element_text(size = 12), axis.title.x = element_text(face="bold", colour="153", size=14), axis.title.y = element_text(face="bold", colour="153", size=14), axis.line.x=element_blank())+ geom_hline(aes(yintercept=0)) reefzones # save graph to file ---- ggsave(reefzones,file="reefzones.png",width = 15, height = 8,units = "cm") # Boxplot Organisms abundance by Depth ---- str(MDZ) # Dataset of depth categories and organisms # Change name of variable ---- colnames(MDZ)[which(names(MDZ) == "Hard.Corals")] <- "Hard Corals" # Change depth variable to factor ---- MDZ$DepthC <- factor(MDZ$DepthC) data2 <- melt(MDZ, id.var = "Depth") #Melt abundance of organisms with depth str(MDZM) depthgraph <- ggplot(data = data2, aes(x=Depth, y=value)) + geom_boxplot(aes(fill=variable)) + coord_flip()+ # flip axis scale_x_discrete(limits=c("3","2","1"),labels=c("15-20", "10-15", "5-10"))+ # Change order and names in the ggplot graph ---- xlab("Depth (m)") + ylab("Percent Cover") + guides(fill=guide_legend(title="Organisms"))+ theme( legend.title=element_blank(), axis.text.x = element_text(colour="153", size=12), axis.text.y = element_text(colour="153", size=12), panel.background = element_rect(fill="white"), panel.grid.minor=element_blank(), panel.grid.major=element_blank(), legend.text = element_text(size = 12), axis.title.x = element_text(face="bold", colour="153", size=14), axis.title.y = element_text(face="bold", colour="153", size=14))+ guides(fill = guide_legend(reverse=TRUE))+ geom_hline(aes(yintercept=0))+ geom_vline(aes(xintercept=0)) depthgraph # save graph to file ---- ggsave(depthgraph,file="depthgraph.png",width = 15, height = 8,units = "cm") ####### non metric MultiDimensional Scaling ### ---- library(vegan) ##Database with abundance of organisms, depth and reef zones dmat <- vegdist(database, method="bray") # Species distance matrix spMDS <- metaMDS(dmat) plot(spMDS,type='n', xlim=c(-1, 0.5)) points(spMDS$points,pch=16,col=as.numeric(database$Zone), cex=2) legend('bottomright',legend=c("Crest", "Leeward", "Windward"), col = c(2,1,3),pch=16,inset=0.0000001, cex = .6) ##### ANOSIM ### ---- anosim(dmat,factor(mada$Zona)) #ANOSIM statistic R: 0.2814 #Significance: 0.001 ##### PERMANOVA ### ---- adonis(dmat~factor(mada$Zona)) #P = 0.001 *** ### Interpolations Cross-validation Graphs ### ---- library(tidyr) library(dplyr) library(cowplot) library(grid) library(gtable) CV <- read.csv("Crossvalidation database.csv") # Database containing values of R2 and Mean Error of each group of organisms per sampling distance Oerrors<-CV%>% filter(Organisms=="Octocorals") #Select only octocorals Oerrors Maerrors<-CV%>% filter(Organisms=="Macroalgae") #Select only Macroalgae Maerrors Serrors<-CV%>% filter(Organisms=="Sponges") #Select only Sponges Serrors Mierrors<-CV%>% filter(Organisms=="Millepora") #Select only Millepora Mierrors Zerrors<-CV%>% filter(Organisms=="Zoanthids") #Select only Zoanthids Zerrors # Distance vs errors # Octocoral Mean Error OctoME <- ggplot(Oerrors, aes(x=Distance, y=ME.,fill=Method, color=Method))+ geom_point(size=3, aes(color=factor(Method)))+ geom_smooth(method= "lm", formula = y ~ x + I(x^2), se=FALSE)+ # xlab('Sampling Distance (m)') + ylab("Mean Error")+ theme( axis.text.x = element_text(colour="153", size=12), axis.text.y = element_text(colour="153", size=12), panel.background = element_rect(fill="white"), panel.grid.minor=element_blank(), panel.grid.major=element_blank(), legend.text = element_text(size = 10), legend.position = "null", legend.key.size = unit(.6, "cm"), axis.title.y = element_text(colour="153", size=12, margin= unit(c(0, 0.3, 0, 0), "cm")), axis.title.x = element_blank()) + theme(axis.line.x = element_line(size = 1, colour = "black"), axis.line.y = element_line(color="black", size = 1)) OctoME # Macroalgae Mean Error MacME <- ggplot(Maerrors, aes(x=Distance, y=ME.,fill=Method, color=Method))+ geom_point(size=3, aes(color=factor(Method)))+ geom_smooth(method= "lm", formula = y ~ x + I(x^2), se=FALSE)+ #xlab('Sampling Distance (m)') + ylab("Mean Error")+ theme( axis.text.x = element_text(colour="153", size=12), axis.text.y = element_text(colour="153", size=12), panel.background = element_rect(fill="white"), panel.grid.minor=element_blank(), panel.grid.major=element_blank(), legend.text = element_text(size = 10), legend.position = "null", legend.key.size = unit(.6, "cm"), axis.title.y = element_text(colour="153", size=12, margin= unit(c(0, 0.3, 0, 0), "cm")), axis.title.x = element_blank()) + theme(axis.line.x = element_line(size = 1, colour = "black"), axis.line.y = element_line(color="black", size = 1)) MacME ### Sponges Mean Error SpoME <- ggplot(Serrors, aes(x=Distance, y=ME.,fill=Method, color=Method))+ geom_point(size=3, aes(color=factor(Method)))+ geom_smooth(method= "lm", formula = y ~ x + I(x^2), se=FALSE)+ #xlab('Sampling Distance (m)') + ylab("Mean Error")+ theme( axis.text.x = element_text(colour="153", size=12), axis.text.y = element_text(colour="153", size=12), panel.background = element_rect(fill="white"), panel.grid.minor=element_blank(), panel.grid.major=element_blank(), legend.text = element_text(size = 10), legend.position = "null", legend.key.size = unit(.6, "cm"), axis.title.y = element_text(colour="153", size=12, margin= unit(c(0, 0.3, 0, 0), "cm")), axis.title.x = element_blank()) + theme(axis.line.x = element_line(size = 1, colour = "black"), axis.line.y = element_line(color="black", size = 1)) SpoME ## Millepora Mean Error MilME <- ggplot(Mierrors, aes(x=Distance, y=ME.,fill=Method, color=Method))+ geom_point(size=3, aes(color=factor(Method)))+ geom_smooth(method= "lm", formula = y ~ x + I(x^2), se=FALSE)+ #xlab('Sampling Distance (m)') + ylab("Mean Error")+ theme( axis.text.x = element_text(colour="153", size=12), axis.text.y = element_text(colour="153", size=12), panel.background = element_rect(fill="white"), panel.grid.minor=element_blank(), panel.grid.major=element_blank(), legend.text = element_text(size = 10), legend.position = "null", legend.key.size = unit(.6, "cm"), axis.title.y = element_text(colour="153", size=12, margin= unit(c(0, 0.3, 0, 0), "cm")), axis.title.x = element_blank()) + theme(axis.line.x = element_line(size = 1, colour = "black"), axis.line.y = element_line(color="black", size = 1)) MilME ## Zoanthids Mean Error ZoaME <- ggplot(Zerrors, aes(x=Distance, y=ME.,fill=Method, color=Method))+ geom_point(size=3, aes(color=factor(Method)))+ geom_smooth(method= "lm", formula = y ~ x + I(x^2), se=FALSE)+ xlab('Sampling Distance (m)') + ylab("Mean Error")+ theme( axis.text.x = element_text(colour="153", size=12), axis.text.y = element_text(colour="153", size=12), panel.background = element_rect(fill="white"), panel.grid.minor=element_blank(), panel.grid.major=element_blank(), legend.text = element_text(size = 10), legend.position = "null", legend.key.size = unit(.6, "cm")) + theme(axis.title.y = element_text(colour="153", size=12, margin= unit(c(0, 0.3, 0, 0), "cm")), axis.title.x = element_text(colour="153", size=12, margin= unit(c(0.3, 0, 0, 0), "cm"))) + theme(axis.line.x = element_line(size = 1, colour = "black"), axis.line.y = element_line(color="black", size = 1)) ZoaME #Octcorals R2 OctoR2 <- ggplot(Oerrors, aes(x=Distance, y=R2,fill=Method, color=Method))+ geom_point(size=3, aes(color=factor(Method)))+ geom_smooth(method= "lm", formula = y ~ x + I(x^2), se=FALSE)+ #xlab('Sampling Distance (m)') + ylab(expression(R^{2})) + theme( axis.text.x = element_text(colour="153", size=12), axis.text.y = element_text(colour="153", size=12), panel.background = element_rect(fill="white"), panel.grid.minor=element_blank(), panel.grid.major=element_blank(), legend.text = element_text(size = 10), legend.position = c(0.7, 0.75), legend.key.size = unit(.6, "cm"), axis.title.y = element_text(colour="153", size=12, margin= unit(c(0, 0.3, 0, 0), "cm")), axis.title.x = element_blank()) + theme(axis.line.x = element_line(size = 1, colour = "black"), axis.line.y = element_line(color="black", size = 1)) OctoR2 # Macroalgae R2 MacR2 <- ggplot(Maerrors, aes(x=Distance, y=R2,fill=Method, color=Method))+ geom_point(size=3, aes(color=factor(Method)))+ geom_smooth(method= "lm", formula = y ~ x + I(x^2), se=FALSE)+ #xlab('Sampling Distance (m)') + ylab(expression(R^{2})) + theme( axis.text.x = element_text(colour="153", size=12), axis.text.y = element_text(colour="153", size=12), panel.background = element_rect(fill="white"), panel.grid.minor=element_blank(), panel.grid.major=element_blank(), legend.text = element_text(size = 10), legend.position = "null", legend.key.size = unit(.6, "cm"), axis.title.y = element_text(colour="153", size=12, margin= unit(c(0, 0.3, 0, 0), "cm")), axis.title.x = element_blank()) + theme(axis.line.x = element_line(size = 1, colour = "black"), axis.line.y = element_line(color="black", size = 1)) MacR2 # Sponges R2 SpoR2 <- ggplot(Serrors, aes(x=Distance, y=R2,fill=Method, color=Method))+ geom_point(size=3, aes(color=factor(Method)))+ geom_smooth(method= "lm", formula = y ~ x + I(x^2), se=FALSE)+ #xlab('Sampling Distance (m)') + ylab(expression(R^{2})) + theme( axis.text.x = element_text(colour="153", size=12), axis.text.y = element_text(colour="153", size=12), panel.background = element_rect(fill="white"), panel.grid.minor=element_blank(), panel.grid.major=element_blank(), legend.text = element_text(size = 10), legend.position = "null", legend.key.size = unit(.6, "cm"), axis.title.y = element_text(colour="153", size=12, margin= unit(c(0, 0.3, 0, 0), "cm")), axis.title.x = element_blank()) + theme(axis.line.x = element_line(size = 1, colour = "black"), axis.line.y = element_line(color="black", size = 1)) SpoR2 # Millepora R2 MilR2 <- ggplot(Mierrors, aes(x=Distance, y=R2,fill=Method, color=Method))+ geom_point(size=3, aes(color=factor(Method)))+ geom_smooth(method= "lm", formula = y ~ x + I(x^2), se=FALSE)+ #xlab('Sampling Distance (m)') + ylab(expression(R^{2})) + theme( axis.text.x = element_text(colour="153", size=12), axis.text.y = element_text(colour="153", size=12), panel.background = element_rect(fill="white"), panel.grid.minor=element_blank(), panel.grid.major=element_blank(), legend.text = element_text(size = 10), legend.position = "null", legend.key.size = unit(.6, "cm"), axis.title.y = element_text(colour="153", size=12, margin= unit(c(0, 0.3, 0, 0), "cm")), axis.title.x = element_blank()) + theme(axis.line.x = element_line(size = 1, colour = "black"), axis.line.y = element_line(color="black", size = 1)) MilR2 # Zoanthids R2 ZoaR2 <- ggplot(Zerrors, aes(x=Distance, y=R2,fill=Method, color=Method))+ geom_point(size=3, aes(color=factor(Method)))+ geom_smooth(method= "lm", formula = y ~ x + I(x^2), se=FALSE)+ xlab('Sampling Distance (m)') + ylab(expression(R^{2})) + theme( axis.text.x = element_text(colour="153", size=12), axis.text.y = element_text(colour="153", size=12), panel.background = element_rect(fill="white"), panel.grid.minor=element_blank(), panel.grid.major=element_blank(), legend.text = element_text(size = 10), legend.position = 'null', legend.key.size = unit(.6, "cm")) + theme(axis.title.y = element_text(colour="153", size=12, margin= unit(c(0, 0.3, 0, 0), "cm")), axis.title.x = element_text(colour="153", size=12, margin= unit(c(0.3, 0, 0, 0), "cm"))) + theme(axis.line.x = element_line(size = 1, colour = "black"), axis.line.y = element_line(color="black", size = 1)) ZoaR2 ####### Crossvalidation Graphs United ### ---- Allgraphs <- plot_grid(OctoME, OctoR2, MacME, MacR2, SpoME, SpoR2, MilME, MilR2, ZoaME, ZoaR2, align="v", labels = c("Octocorals", "", "Macroalgae", "", "Sponges", "", "Millepora", "", "Zoanthids", ""), ncol = 2, nrow = 5, label_x=0.15) help("plot_grid") Allgraphs ggsave(Allgraphs,file="All Cross Validation.jpeg",width = 20, height = 27,units = "cm")