######## PLOTS OF MODEL RESULTS ######## rm(list=ls(all=T)) #Clean environment setwd("C:/Users/lucas/Desktop/Doctorado/Cántaros/3) Results") #Change to your file location set.seed(777) #Make the results reproducible #Packages library(ggplot2) library(gtable) library(ggpubr) library(lemon) #Set plot theme preferences theme_set(theme_bw(18)) theme_update(panel.grid = element_blank(), legend.text = element_text(size = 18), legend.title = element_blank(), axis.text.y = element_text(size = 14), strip.background = element_blank(), strip.placement = "outside", axis.title.x = element_blank()) #Function to place legend in empty space of the plot shift_legend <- function(p) { # ... # to grob gp <- ggplotGrob(p) facet.panels <- grep("^panel", gp[["layout"]][["name"]]) empty.facet.panels <- sapply(facet.panels, function(i) "zeroGrob" %in% class(gp[["grobs"]][[i]])) empty.facet.panels <- facet.panels[empty.facet.panels] # establish name of empty panels empty.facet.panels <- gp[["layout"]][empty.facet.panels, ] names <- empty.facet.panels$name # example of names: #[1] "panel-3-2" "panel-3-3" # now we just need a simple call to reposition the legend reposition_legend(p, 'center', panel=names) } prey_names <- list('1' = 'Bacteria', '2' = 'Pcy', '3' = 'Nanoflagellates', '4' = 'Micro-algae', '5' = 'CPcy') prey_lab <- function(variable,value){ return(prey_names[value]) } ### PLOT 1: PREY BIOMASS ### prey_biov <- read.csv('prey_biov.csv') g_x24 <- ggplot(data = subset(prey_biov, time == 24), aes(x = trtm, y = value)) + geom_boxplot(aes(fill = zoop), position = position_dodge2(preserve = "single")) + scale_fill_manual(name = 'Treatment', labels = c('Control', 'Cladoceran', 'Copepod'), values = c('gray95', 'cyan3', 'coral')) + labs(y = expression(paste("Biomass (", mm^3, " ", L^-1, ") after 24 hr"))) + scale_y_continuous(labels = scales::number_format(accuracy = 0.01)) + facet_wrap(~comp, scales= "free_y", nrow = 2, strip.position = "top", labeller = prey_lab) shift_legend(g_x24) g_x48 <- ggplot(data = subset(prey_biov, time == 48), aes(x = trtm, y = value)) + geom_boxplot(aes(fill = zoop), position = position_dodge2(preserve = "single")) + scale_fill_manual(name = 'Treatment', labels = c('Control', 'Cladoceran', 'Copepod'), values = c('gray95', 'cyan3', 'coral')) + labs(y = expression(paste("Biomass (", mm^3, " ", L^-1, ") after 48 hr"))) + scale_y_continuous(labels = scales::number_format(accuracy = 0.01)) + facet_wrap(~comp, scales= "free_y", nrow = 2, strip.position = "top", labeller = prey_lab) shift_legend(g_x48) ### PLOT 2: PICY AGGREGATES### aggr <- read.csv('CPCy colony size.csv') g_ag24 <- ggplot(data = subset(aggr, time == 24), aes(x = trtm, y = value)) + geom_boxplot(aes(fill = zoop), position = position_dodge2(preserve = "single")) + scale_fill_manual(name = 'Treatment', labels = c('Control', 'Cladoceran', 'Copepod'), values = c('gray95', 'cyan3', 'coral')) + theme(axis.title.y = element_text(size = 14)) + scale_y_continuous(limits = c(0, 35)) + labs(y = expression(paste("CPcy size (cells ", colony^-1, ") after 24 hr"))) g_ag24 g_ag48 <- ggplot(data = subset(aggr, time == 48), aes(x = trtm, y = value)) + geom_boxplot(aes(fill = zoop), position = position_dodge2(preserve = "single")) + scale_fill_manual(name = 'Treatment', labels = c('Control', 'Cladoceran', 'Copepod'), values = c('gray95', 'cyan3', 'coral')) + theme(axis.title.y = element_text(size = 14)) + scale_y_continuous(limits = c(0, 30)) + labs(y = expression(paste("CPcy size (cells ", colony^-1, ") after 48 hr"))) g_ag48 ggarrange(g_ag24, g_ag48, nrow = 1, common.legend = TRUE, legend = 'bottom') ### PLOT 3: TDP and TPP### TP <- read.csv('phosphorus.csv') g_DP_24 <- ggplot(data = subset(TP, data == 'DP' & time == 24), aes(x = trtm, y = value)) + geom_boxplot(aes(fill = zoop), position = position_dodge2(preserve = "single")) + scale_fill_manual(name = 'Treatment', labels = c('Control', 'Cladoceran', 'Copepod'), values = c('gray95', 'cyan3', 'coral')) + theme(axis.title.y = element_text(size = 14)) + labs(y = expression(paste("Dissolved P (", mu, "mol ", L^-1, ") after 24 hr"))) + scale_y_continuous(labels = scales::number_format(accuracy = 0.01),limits = c(0, 0.15)) g_DP_24 g_PP_24 <- ggplot(data = subset(TP, data == 'PP' & time == 24), aes(x = trtm, y = value)) + geom_boxplot(aes(fill = zoop), position = position_dodge2(preserve = "single")) + scale_fill_manual(name = 'Treatment', labels = c('Control', 'Cladoceran', 'Copepod'), values = c('gray95', 'cyan3', 'coral')) + theme(axis.title.y = element_text(size = 14)) + labs(y = expression(paste("Particulate P (", mu, "mol ", L^-1, ") after 24 hr"))) + scale_y_continuous(labels = scales::number_format(accuracy = 0.01),limits = c(0, 0.15)) g_PP_24 g_DP_48 <- ggplot(data = subset(TP, data == 'DP' & time == 48), aes(x = trtm, y = value)) + geom_boxplot(aes(fill = zoop), position = position_dodge2(preserve = "single")) + scale_fill_manual(name = 'Treatment', labels = c('Control', 'Cladoceran', 'Copepod'), values = c('gray95', 'cyan3', 'coral')) + theme(axis.title.y = element_text(size = 14)) + labs(y = expression(paste("Dissolved P (", mu, "mol ", L^-1, ") after 48 hr"))) + scale_y_continuous(labels = scales::number_format(accuracy = 0.01),limits = c(0, 0.15)) g_DP_48 g_PP_48 <- ggplot(data = subset(TP, data == 'PP' & time == 48), aes(x = trtm, y = value)) + geom_boxplot(aes(fill = zoop), position = position_dodge2(preserve = "single")) + scale_fill_manual(name = 'Treatment', labels = c('Control', 'Cladoceran', 'Copepod'), values = c('gray95', 'cyan3', 'coral')) + theme(axis.title.y = element_text(size = 14)) + labs(y = expression(paste("Particulate P (", mu, "mol ", L^-1, ") after 48 hr"))) + scale_y_continuous(labels = scales::number_format(accuracy = 0.01),limits = c(0, 0.15)) g_PP_48 ggarrange(g_DP_24, g_PP_24, g_DP_48, g_PP_48, common.legend = TRUE, legend = 'bottom') ### PLOT 4: ZOOPLANKTON GRAZING ### graz <- read.csv('grazing.csv') g_graz <- ggplot(data = graz, aes(x = factor(pre), y = value)) + geom_boxplot(aes(fill = zoo)) + scale_fill_manual(values = c('cyan3', 'coral')) + labs(y = expression(paste("% Biomass ", ind^-1, day^-1))) + scale_y_continuous(limits = c(0, 15)) + theme(axis.title.y = element_text(size = 14)) + scale_x_discrete(labels = c('Bacteria', 'Pcy', 'Nanoflagellates', 'Algae', 'CPcy')) size <- read.csv('grazed_size.csv') g_size <- ggplot(data = size) + theme(axis.title.x = element_text(size = 14)) + geom_density(aes(y = ..density.. * 100, x = value, fill = zoop), alpha = 0.5) + scale_fill_manual(values = c('cyan3','coral')) + labs(x = expression(paste("Prey size (", mu, "m)")), y = expression(paste("% from total grazing ", ind^-1))) + theme(legend.position = 'left', legend.title = element_blank(), legend.text = element_text(size = 14), axis.title.y = element_text(size = 14)) ggarrange(g_graz, g_size, common.legend = TRUE, legend = 'bottom', nrow = 2) ### PLOT 5: PREY P QUOTA### prey_quot <- read.csv('P_quotas.csv') g_Q48 <- ggplot(data = subset(prey_quot, time == 48), aes(x = trtm, y = value * 1000)) + geom_boxplot(aes(fill = zoop), position = position_dodge2(preserve = "single")) + scale_fill_manual(name = 'Treatment', labels = c('Control', 'Cladoceran', 'Copepod'), values = c('gray95', 'cyan3', 'coral')) + labs(y = expression(paste("P Quota (nmol ", mm^-3, ") after 48 hr"))) + scale_y_continuous(labels = scales::number_format(accuracy = 0.1)) + facet_wrap(~comp, scales= "free_y", nrow = 2, strip.position = "top", labeller = prey_lab) shift_legend(g_Q48) g_Q72 <- ggplot(data = subset(prey_quot, time == 72), aes(x = trtm, y = value * 1000)) + geom_boxplot(aes(fill = zoop), position = position_dodge2(preserve = "single")) + scale_fill_manual(name = 'Treatment', labels = c('Control', 'Cladoceran', 'Copepod'), values = c('gray95', 'cyan3', 'coral')) + labs(y = expression(paste("P Quota (nmol ", mm^-3, ") after 72 hr"))) + scale_y_continuous(labels = scales::number_format(accuracy = 0.1)) + facet_wrap(~comp, scales= "free_y", nrow = 2, strip.position = "top", labeller = prey_lab) shift_legend(g_Q72) ### PLOT 6: ZOOPLANKTON RECYCLING ### recy <- read.csv('P_recycling.csv') g_recy <- ggplot(data = recy, aes(x = zoop, y = value * 100)) + geom_boxplot(aes(fill = sorc)) + scale_fill_manual(values = c('white', 'grey')) + labs(y = expression(paste("nmol P ", ind^-1, day^-1)), x = '') + scale_x_discrete(labels = c('Cladoceran', 'Copepod')) + scale_y_continuous(limits = c(0.1, 0.5)) + theme(legend.title = element_blank(), legend.position = 'top') g_recy ######