Skip to content

Commit 988f85b

Browse files
R code for figures and analyses
1 parent 6d54efe commit 988f85b

21 files changed

+3376
-0
lines changed
Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
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

Figures&Code/Figure_2/dissolved_oxygen.csv

Whitespace-only changes.

Figures&Code/Figure_2/monitor_param.csv

Whitespace-only changes.

Figures&Code/Figure_2/monitor_param_LONG.csv

Whitespace-only changes.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
sampling_timept,time,dilution_rate
2+
1,1.7,A
3+
2,6.82,A
4+
3,10.5,A
5+
4,15.46,A
6+
5,16.46,B
7+
6,17.13,B
8+
7,19.84,B
9+
8,21.47,B
10+
9,19.84,B
11+
10,21.47,C
12+
11,21.8,C
13+
12,22.39,C
14+
13,22.8,C
15+
14,23.55,C
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Figure 2 in Meg/Ashley SES Manuscript
2+
# Environmental parameters from chemostats
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+
pretty.theme <- function(){
13+
theme_bw()+
14+
theme(axis.text.x=element_text(size=14, color = "black", angle = 0, hjust = 1),
15+
axis.text.y=element_text(size=14, color = "black"),
16+
axis.title.x=element_text(size=20, color = "black"),
17+
axis.title.y=element_text(size=20, color = "black"),
18+
panel.grid.major.x=element_blank(),
19+
panel.grid.minor.x=element_blank(),
20+
panel.grid.minor.y=element_blank(),
21+
panel.grid.major.y=element_blank(),
22+
plot.margin = unit(c(0.5, 0.5, 0.5, 0.5), units = , "cm"),
23+
plot.title = element_text(size=20),
24+
legend.text = element_text(size=12, face="italic"),
25+
legend.title = element_blank(),
26+
legend.position="none")
27+
}
28+
29+
nuts_data <- read.csv("new_nutrients.csv", header = TRUE)
30+
31+
nitrate_plot <- ggplot(nuts_data, aes(x = days_after, y = nitrate_conc)) +
32+
annotate("rect", fill = "#2B5B6C", alpha = 0.4,
33+
xmin = 0, xmax = 15.71,
34+
ymin = -Inf, ymax = Inf) +
35+
annotate("rect", fill = "#E34F33", alpha = 0.4,
36+
xmin = 15.71, xmax = 20.79,
37+
ymin = -Inf, ymax = Inf) +
38+
annotate("rect", fill = "#FFC87E", alpha = 0.4,
39+
xmin = 20.79, xmax = 25,
40+
ymin = -Inf, ymax = Inf) +
41+
geom_point(aes(shape = chemostat_ID, color = chemostat_ID), size = 2) +
42+
geom_line(aes(color = chemostat_ID, linetype = chemostat_ID)) +
43+
labs(y = expression (""), x = "Days After Start") +
44+
scale_color_manual(values = c("black", "black")) +
45+
pretty.theme()
46+
nitrate_plot
47+
48+
phosphate_plot <- ggplot(nuts_data, aes(x = days_after, y = phos_conc)) +
49+
annotate("rect", fill = "#2B5B6C", alpha = 0.4,
50+
xmin = 0, xmax = 15.71,
51+
ymin = -Inf, ymax = Inf) +
52+
annotate("rect", fill = "#E34F33", alpha = 0.4,
53+
xmin = 15.71, xmax = 20.79,
54+
ymin = -Inf, ymax = Inf) +
55+
annotate("rect", fill = "#FFC87E", alpha = 0.4,
56+
xmin = 20.79, xmax = 25,
57+
ymin = -Inf, ymax = Inf) +
58+
geom_point(aes(shape = chemostat_ID, color = chemostat_ID), size = 2) +
59+
geom_line(aes(color = chemostat_ID, linetype = chemostat_ID)) +
60+
labs(y = expression (""), x = "Days After Start") +
61+
scale_color_manual(values = c("black", "black")) +
62+
pretty.theme()
63+
phosphate_plot
64+
65+
ammonium_plot <- ggplot(nuts_data, aes(x = days_after, y = ammonium_con)) +
66+
annotate("rect", fill = "#2B5B6C", alpha = 0.4,
67+
xmin = 0, xmax = 15.71,
68+
ymin = -Inf, ymax = Inf) +
69+
annotate("rect", fill = "#E34F33", alpha = 0.4,
70+
xmin = 15.71, xmax = 20.79,
71+
ymin = -Inf, ymax = Inf) +
72+
annotate("rect", fill = "#FFC87E", alpha = 0.4,
73+
xmin = 20.79, xmax = 25,
74+
ymin = -Inf, ymax = Inf) +
75+
geom_point(aes(shape = chemostat_ID, color = chemostat_ID), size = 2) +
76+
geom_line(aes(color = chemostat_ID, linetype = chemostat_ID)) +
77+
labs(y = expression (""), x = "Days After Start") +
78+
scale_color_manual(values = c("black", "black")) +
79+
pretty.theme()
80+
ammonium_plot
81+
82+
DOC_plot <- ggplot(nuts_data, aes(x = days_after, y = doc_conc_mmol)) +
83+
annotate("rect", fill = "#2B5B6C", alpha = 0.4,
84+
xmin = 0, xmax = 15.71,
85+
ymin = -Inf, ymax = Inf) +
86+
annotate("rect", fill = "#E34F33", alpha = 0.4,
87+
xmin = 15.71, xmax = 20.79,
88+
ymin = -Inf, ymax = Inf) +
89+
annotate("rect", fill = "#FFC87E", alpha = 0.4,
90+
xmin = 20.79, xmax = 25,
91+
ymin = -Inf, ymax = Inf) +
92+
geom_point(aes(shape = chemostat_ID, color = chemostat_ID), size = 2) +
93+
geom_line(aes(color = chemostat_ID, linetype = chemostat_ID)) +
94+
labs(y = expression (""), x = "Days After Start") +
95+
scale_color_manual(values = c("black", "black")) +
96+
pretty.theme()
97+
DOC_plot
98+

0 commit comments

Comments
 (0)