|
| 1 | +# Figure 2 in Meg/Ashley SES Manuscript |
| 2 | +# Environmental parameters from chemostats (pH, CO2, O2, Dissolved O2) |
| 3 | + |
| 4 | +# UPLOAD DATA---- |
| 5 | +path = "/Users/abulseco/Dropbox/MBL_Postdoc/Experiments/2018_Pilot_SESProject/Microbial_Data/Downloads_from_VAMPS/JJV_MEG_Bv4v5" |
| 6 | +setwd("~/Dropbox/MBL_Postdoc/Experiments/2018_Pilot_SESProject/Microbial_Data/Downloads_from_VAMPS/JJV_MEG_Bv4v5") |
| 7 | + |
| 8 | +# Load necessary libraries |
| 9 | +library("ggplot2") |
| 10 | +library(patchwork) |
| 11 | + |
| 12 | +# This is a slightly different theme function from others |
| 13 | +pretty.theme <- function(){ |
| 14 | + theme_bw()+ |
| 15 | + theme(axis.text.x=element_text(size=14, color = "black", angle = 0, hjust = 1), |
| 16 | + axis.text.y=element_text(size=14, color = "black"), |
| 17 | + axis.title.x=element_text(size=20, color = "black"), |
| 18 | + axis.title.y=element_text(size=20, color = "black"), |
| 19 | + panel.grid.major.x=element_blank(), |
| 20 | + panel.grid.minor.x=element_blank(), |
| 21 | + panel.grid.minor.y=element_blank(), |
| 22 | + panel.grid.major.y=element_blank(), |
| 23 | + plot.margin = unit(c(0.5, 0.5, 0.5, 0.5), units = , "cm"), |
| 24 | + plot.title = element_text(size=20), |
| 25 | + legend.text = element_text(size=12, face="italic"), |
| 26 | + legend.title = element_blank(), |
| 27 | + legend.position="none") |
| 28 | +} |
| 29 | + |
| 30 | +theme.exp1 <- function(){ |
| 31 | + theme_bw()+ |
| 32 | + theme(axis.text.x=element_text(size=18, vjust=1, hjust=1, color = "black"), |
| 33 | + axis.text.y=element_text(size=18, color = "black"), |
| 34 | + axis.title.x=element_text(size=14, face="plain"), |
| 35 | + axis.title.y=element_text(size=14, face="plain"), |
| 36 | + panel.grid.major.x=element_blank(), |
| 37 | + panel.grid.minor.x=element_blank(), |
| 38 | + panel.grid.minor.y=element_blank(), |
| 39 | + panel.grid.major.y=element_blank(), |
| 40 | + plot.title = element_text(size=20, vjust=1, hjust=0.5), |
| 41 | + legend.text = element_text(size=12, face="italic"), |
| 42 | + legend.title = element_blank(), |
| 43 | + axis.title = element_blank()) |
| 44 | +} |
| 45 | + |
| 46 | +# Read in the data (dissolved O2 had a different output) |
| 47 | +monitor_var <- read.csv("monitor_param_LONG.csv", header = T) |
| 48 | +str(monitor_var) |
| 49 | +dissolved_oxy <- read.csv("dissolved_oxygen.csv", header = T) |
| 50 | + |
| 51 | +# pH Plot |
| 52 | +############################################################################# |
| 53 | +############################################################################# |
| 54 | +ph_plot <- ggplot(monitor_var, group = chemostat_ID, aes(x = time, y = ph)) + |
| 55 | + annotate("rect", fill = "#2B5B6C", alpha = 0.4, |
| 56 | + xmin = 0, xmax = 15.71, |
| 57 | + ymin = -Inf, ymax = Inf) + |
| 58 | + annotate("rect", fill = "#E34F33", alpha = 0.4, |
| 59 | + xmin = 15.71, xmax = 20.79, |
| 60 | + ymin = -Inf, ymax = Inf) + |
| 61 | + annotate("rect", fill = "#FFC87E", alpha = 0.4, |
| 62 | + xmin = 20.79, xmax = 25, |
| 63 | + ymin = -Inf, ymax = Inf) + |
| 64 | + # geom_vline(xintercept = 15.71, color = "black", linetype = "dashed") + |
| 65 | + # geom_vline(xintercept = 20.79, color = "black", linetype = "dashed") + |
| 66 | + # scale_fill_manual(values = c("#3399CC", "#003399", linetype = "dashed")) + |
| 67 | + scale_color_manual(values = c("black", "gray45", linetype = "dashed")) + |
| 68 | + # facet_wrap(chemostat_ID~.) + |
| 69 | + geom_line(size = 0.75, aes(linetype = chemostat_ID)) + |
| 70 | + pretty.theme() + |
| 71 | + theme(strip.background = element_blank(), # Overriding some of the original theme |
| 72 | + strip.text.x = element_blank(), |
| 73 | + axis.title.x=element_blank(), |
| 74 | + axis.title.y=element_blank(), |
| 75 | + legend.position = "none") |
| 76 | +ph_plot |
| 77 | + |
| 78 | +# CO2 Plot |
| 79 | +############################################################################# |
| 80 | +############################################################################# |
| 81 | +CO2_plot <- ggplot(monitor_var, group = chemostat_ID, aes(x = time, y = carbon_dio_perc)) + |
| 82 | + annotate("rect", fill = "#2B5B6C", alpha = 0.4, |
| 83 | + xmin = 0, xmax = 15.71, |
| 84 | + ymin = -Inf, ymax = Inf) + |
| 85 | + annotate("rect", fill = "#E34F33", alpha = 0.4, |
| 86 | + xmin = 15.71, xmax = 20.79, |
| 87 | + ymin = -Inf, ymax = Inf) + |
| 88 | + annotate("rect", fill = "#FFC87E", alpha = 0.4, |
| 89 | + xmin = 20.79, xmax = 25, |
| 90 | + ymin = -Inf, ymax = Inf) + |
| 91 | + # geom_vline(xintercept = 15.71, color = "black", linetype = "dashed") + |
| 92 | + # geom_vline(xintercept = 20.79, color = "black", linetype = "dashed") + |
| 93 | + # scale_fill_manual(values = c("#3399CC", "#003399", linetype = "dashed")) + |
| 94 | + scale_color_manual(values = c("black", "gray45", linetype = "dashed")) + |
| 95 | + # facet_wrap(chemostat_ID~.) + |
| 96 | + geom_line(size = 0.75, aes(linetype = chemostat_ID)) + |
| 97 | + pretty.theme() + |
| 98 | + theme(strip.background = element_blank(), |
| 99 | + strip.text.x = element_blank(), |
| 100 | + axis.title.x=element_blank(), |
| 101 | + axis.text.x=element_blank(), |
| 102 | + axis.title.y=element_blank(), |
| 103 | + legend.position = "none") |
| 104 | +CO2_plot |
| 105 | + |
| 106 | +# O2 Plot |
| 107 | +############################################################################# |
| 108 | +############################################################################# |
| 109 | +O2_plot <- ggplot(monitor_var, group = chemostat_ID, aes(x = time, y = oxygen_perc)) + |
| 110 | + annotate("rect", fill = "#2B5B6C", alpha = 0.4, |
| 111 | + xmin = 0, xmax = 15.71, |
| 112 | + ymin = -Inf, ymax = Inf) + |
| 113 | + annotate("rect", fill = "#E34F33", alpha = 0.4, |
| 114 | + xmin = 15.71, xmax = 20.79, |
| 115 | + ymin = -Inf, ymax = Inf) + |
| 116 | + annotate("rect", fill = "#FFC87E", alpha = 0.4, |
| 117 | + xmin = 20.79, xmax = 25, |
| 118 | + ymin = -Inf, ymax = Inf) + |
| 119 | + # geom_vline(xintercept = 15.71, color = "black", linetype = "dashed") + |
| 120 | + # geom_vline(xintercept = 20.79, color = "black", linetype = "dashed") + |
| 121 | + # scale_fill_manual(values = c("#3399CC", "#003399", linetype = "dashed")) + |
| 122 | + scale_color_manual(values = c("black", "gray45", linetype = "dashed")) + |
| 123 | + # facet_wrap(chemostat_ID~.) + |
| 124 | + geom_line(size = 0.75, aes(linetype = chemostat_ID)) + |
| 125 | + pretty.theme() + |
| 126 | + theme(strip.background = element_blank(), |
| 127 | + strip.text.x = element_blank(), |
| 128 | + axis.title.x=element_blank(), |
| 129 | + axis.text.x=element_blank(), |
| 130 | + axis.title.y=element_blank(), |
| 131 | + legend.position = "none") |
| 132 | +O2_plot |
| 133 | + |
| 134 | +# Dissolved O2 Plot |
| 135 | +############################################################################# |
| 136 | +############################################################################# |
| 137 | +diss_O2_plot <- ggplot(dissolved_oxy, group = chemostat_ID, aes(x = time, y = diss_o2)) + |
| 138 | + annotate("rect", fill = "#2B5B6C", alpha = 0.4, |
| 139 | + xmin = 0, xmax = 15.71, |
| 140 | + ymin = -Inf, ymax = Inf) + |
| 141 | + annotate("rect", fill = "#E34F33", alpha = 0.4, |
| 142 | + xmin = 15.71, xmax = 20.79, |
| 143 | + ymin = -Inf, ymax = Inf) + |
| 144 | + annotate("rect", fill = "#FFC87E", alpha = 0.4, |
| 145 | + xmin = 20.79, xmax = 25, |
| 146 | + ymin = -Inf, ymax = Inf) + |
| 147 | + # geom_vline(xintercept = 15.71, color = "black", linetype = "dashed") + |
| 148 | + # geom_vline(xintercept = 20.79, color = "black", linetype = "dashed") + |
| 149 | + # scale_fill_manual(values = c("#3399CC", "#003399", linetype = "dashed")) + |
| 150 | + scale_color_manual(values = c("black", "gray45", linetype = "dashed")) + |
| 151 | + # facet_wrap(chemostat_ID~.) + |
| 152 | + geom_line(size = 0.75, aes(linetype = chemostat_ID)) + |
| 153 | + pretty.theme() + |
| 154 | + theme(strip.background = element_blank(), |
| 155 | + strip.text.x = element_blank(), |
| 156 | + axis.title.x=element_blank(), |
| 157 | + axis.text.x=element_blank(), |
| 158 | + axis.title.y=element_blank(), |
| 159 | + legend.position = "none") |
| 160 | +diss_O2_plot |
| 161 | + |
| 162 | +# Then using patchwork, connect all the plots |
| 163 | +# After exporting to PDF, use InkScape to add in timeline along the top |
| 164 | +# axes labels along the left of each plot, and legend for MC1 and MC2. |
| 165 | + |
| 166 | +pdf("Fig2.pdf") |
| 167 | +CO2_plot + O2_plot + diss_O2_plot + ph_plot + plot_layout(ncol = 1) |
| 168 | +dev.off() |
| 169 | + |
| 170 | +# CREATING A TIMELINE PLOT |
| 171 | +# FROM THIS AWESOME BLOG POST: https://benalexkeen.com/creating-a-timeline-graphic-using-r-and-ggplot2/ |
| 172 | +############################################################################# |
| 173 | +############################################################################# |
| 174 | +# (But it is not being used in the figure) |
| 175 | +df <- read.csv("sampling_timeline_final.csv") |
| 176 | + |
| 177 | +status_levels <- c("A", "B", "C") |
| 178 | +status_colors <- c("#2B5B6C", "#E34F33", "#FFC87E") |
| 179 | + |
| 180 | +df$dilution_rate <- factor(df$dilution_rate, levels=status_levels, ordered=TRUE) |
| 181 | + |
| 182 | +# PLOT |
| 183 | +timeline_plot<-ggplot(df,aes(x=time,y=0, col=dilution_rate)) |
| 184 | +# timeline_plot<-timeline_plot+labs(col="dilution_rate") |
| 185 | +timeline_plot<-timeline_plot+scale_color_manual(values=status_colors, labels=status_levels, drop = FALSE) |
| 186 | +timeline_plot<-timeline_plot+theme_classic() |
| 187 | + |
| 188 | +# Plot horizontal black line for timeline |
| 189 | +timeline_plot<-timeline_plot+geom_hline(yintercept=0, |
| 190 | + color = "black", size=0.3) |
| 191 | + |
| 192 | +# Plot scatter points at zero and date |
| 193 | +timeline_plot<-timeline_plot+geom_point(aes(y=0), size=2) |
| 194 | + |
| 195 | +# Don't show axes, appropriately position legend |
| 196 | +timeline_plot<-timeline_plot+theme(axis.line.y=element_blank(), |
| 197 | + axis.text.y=element_blank(), |
| 198 | + axis.title.x=element_blank(), |
| 199 | + axis.title.y=element_blank(), |
| 200 | + axis.ticks.y=element_blank(), |
| 201 | + axis.text.x =element_blank(), |
| 202 | + axis.ticks.x =element_blank(), |
| 203 | + axis.line.x =element_blank(), |
| 204 | + legend.title = element_blank(), |
| 205 | + legend.position="none" |
| 206 | +) + scale_x_continuous(limits=c(0, 25)) + |
| 207 | + scale_y_continuous(limits=c(-1,1)) |
| 208 | + |
| 209 | +timeline_plot |
0 commit comments