-
Notifications
You must be signed in to change notification settings - Fork 0
/
Graphing_Ellery.Rmd
427 lines (386 loc) · 17.1 KB
/
Graphing_Ellery.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
---
title: "Graphing_Ellery"
author: "Ellery Vaughan"
date: "2023-09-28"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
# Making second round of figures
```{r load necessary packages}
library(tidyverse)
```
```{r load data}
site_df <- read_csv("../../sparc-soil-p_site-avgs_mineral_0-10.csv")
```
```{r copied from Nick's script}
site_df <- site_df %>%
# Get a column that is the dataset number
tidyr::separate_wider_delim(cols = dataset_simp, delim = "_", too_few = "align_start",
names = c("dataset_dup", "dataset_num"), cols_remove = F) %>%
# Drop now-duplicated dataset column
dplyr::select(-dataset_dup) %>%
# If no number, fill with 1
dplyr::mutate(dataset_num = ifelse(is.na(dataset_num), yes = 1, no = dataset_num))
# Check structure
dplyr::glimpse(site_df)
# adding column for HCl/total P
site_df <- site_df %>%
mutate(HCl_Total_P = (mean_slow.P_conc_mg.kg/mean_total.P_conc_mg.kg))
# Make one version each for N and C plotting respectively
site_n <- dplyr::filter(.data = site_df, !is.na(mean_N_conc_percent))
site_c <- dplyr::filter(.data = site_df, !is.na(mean_C_conc_percent))
```
```{r Graph housekeeping}
# Pick a color palette for LTERs
lter_colors <- c("ARC" = "#264653", "BNZ" = "#2a9d8f", "Brazil" = "#e9c46a",
"Calhoun" = "#f4a261", "CWT" = "#7209b7", "FCE" = "#00b4d8",
"HBR" = "#e76f51",
"JRN" = "#606c38", "KNZ" = "#ffafcc", "LUQ" = "#d9ed92",
"NWT" = "#06d6a0", "SEV" = "#d62828")
# Shapes for dataset numbers
data_shapes <- c("1" = 21, "2" = 22, "3" = 24, "4" = 23)
# Define error bars for metrics we're sure to graph
## Carbon SE
c_se <- geom_errorbar(aes(ymax = mean_C_conc_percent + std.error_C_conc_percent,
ymin = mean_C_conc_percent - std.error_C_conc_percent),
width = 0, na.rm = T)
## Nitrogen SE
n_se <- geom_errorbar(aes(ymax = mean_N_conc_percent + std.error_N_conc_percent,
ymin = mean_N_conc_percent - std.error_N_conc_percent),
width = 0, na.rm = T)
## Slow P SE
slowp_se <- geom_errorbarh(aes(xmax = mean_slow.P_conc_mg.kg + std.error_slow.P_conc_mg.kg,
xmin = mean_slow.P_conc_mg.kg - std.error_slow.P_conc_mg.kg),
height = 0, na.rm = T)
## NaOH P SE
NaOH_se <- geom_errorbarh(aes(xmax = mean_NaOH.P_conc_mg.kg + std.error_NaOH.P_conc_mg.kg,
xmin = mean_NaOH.P_conc_mg.kg - std.error_NaOH.P_conc_mg.kg),
height = 0, na.rm = T)
## Total P SE
totp_se <- geom_errorbarh(aes(xmax = mean_total.P_conc_mg.kg + std.error_total.P_conc_mg.kg,
xmin = mean_total.P_conc_mg.kg - std.error_total.P_conc_mg.kg),
height = 0, na.rm = T)
# ## Total P SE
# totp_se <- geom_errorbarh(aes(xmax = mean_total.P_conc_mg.kg + std.error_total.P_conc_mg.kg,
# xmin = mean_total.P_conc_mg.kg - std.error_total.P_conc_mg.kg),
# height = 0, na.rm = T)
# Custom ggplot theme
sparc_theme <- theme(panel.grid = element_blank(),
panel.background = element_blank(),
axis.line = element_line(color = "black"),
# Facet labels (where applicable)
strip.text = element_text(size = 16),
strip.background = element_rect(color = "black", fill = "white",
linewidth = 1),
# Axis tick mark / title elements
axis.text.y = element_text(size = 14),
axis.text.x = element_text(size = 13),
axis.title = element_text(size = 16),
# Legend tweaks
legend.key = element_blank(),
legend.background = element_blank())
```
```{r Site Average Graphs N and C verus slow and total}
# N% ~ total P
xsite_ntotp <- ggplot(data = site_n, aes(x = mean_total.P_conc_mg.kg, y = mean_N_conc_percent)) +
# Error bars (defined above)
n_se + totp_se +
# Best fit line
geom_smooth(method = "lm", formula = "y ~ x", se = F, color = "black") +
# Points/labels for each dataset
geom_point(aes(fill = lter, shape = dataset_num), size = 3, alpha = 0.95) +
# Customizing theme elements
labs(x = "Mean Total P (mg/kg) ± SE", y = "Mean N (%) ± SE",
shape = "Dataset Number", fill = "LTER") +
scale_shape_manual(values = data_shapes) +
scale_fill_manual(values = lter_colors) +
guides(fill = guide_legend(override.aes = list(shape = 21, size = 6)),
shape = guide_legend(override.aes = list(size = 5))) +
sparc_theme +
theme(legend.position = "none"); xsite_ntotp
# N% ~ slow P
xsite_nslowp <- ggplot(data = site_n, aes(x = mean_slow.P_conc_mg.kg, y = mean_N_conc_percent)) +
# Error bars (defined above)
n_se + slowp_se +
# Best fit line
geom_smooth(method = "lm", formula = "y ~ x", se = F, color = "black") +
# Points/labels for each dataset
geom_point(aes(fill = lter, shape = dataset_num), size = 3, alpha = 0.95) +
# Customizing theme elements
labs(x = "Mean Slow P (mg/kg) ± SE", y = "Mean N (%) ± SE",
shape = "Dataset Number", fill = "LTER") +
scale_shape_manual(values = data_shapes) +
scale_fill_manual(values = lter_colors) +
guides(fill = guide_legend(override.aes = list(shape = 21, size = 6)),
shape = guide_legend(override.aes = list(size = 5))) +
sparc_theme +
theme(legend.position = "none"); xsite_nslowp
# C% ~ total P
xsite_ctotp <- ggplot(data = site_c, aes(x = mean_total.P_conc_mg.kg, y = mean_C_conc_percent)) +
# Error bars (defined above)
c_se + totp_se +
# Best fit line
geom_smooth(method = "lm", formula = "y ~ x", se = F, color = "black") +
# Points/labels for each dataset
geom_point(aes(fill = lter, shape = dataset_num), size = 3, alpha = 0.95) +
# Customizing theme elements
labs(x = "Mean Total P (mg/kg) ± SE", y = "Mean C (%) ± SE",
shape = "Dataset Number", fill = "LTER") +
scale_shape_manual(values = data_shapes) +
scale_fill_manual(values = lter_colors) +
sparc_theme +
guides(fill = F) +
sparc_theme +
theme(legend.position = c(0.4, 0.75),
legend.direction = "horizontal"); xsite_ctotp
# C% ~ slow P
xsite_cslowp <- ggplot(data = site_c, aes(x = mean_slow.P_conc_mg.kg, y = mean_C_conc_percent)) +
# Error bars (defined above)
c_se + slowp_se +
# Best fit line
geom_smooth(method = "lm", formula = "y ~ x", se = F, color = "black") +
# Points/labels for each dataset
geom_point(aes(fill = lter, shape = dataset_num), size = 3, alpha = 0.95) +
# Customizing theme elements
labs(x = "Mean Slow P (mg/kg) ± SE", y = "Mean C (%) ± SE",
shape = "Dataset Number", fill = "LTER") +
scale_shape_manual(values = data_shapes) +
scale_fill_manual(values = lter_colors) +
guides(fill = guide_legend(override.aes = list(shape = 21, size = 6)),
shape = guide_legend(override.aes = list(size = 5))) +
guides(fill = guide_legend(override.aes = list(shape = 21, size = 6)),
shape = guide_legend(override.aes = list(size = 5))) +
guides(shape = F) +
sparc_theme +
theme(legend.position = c(0.6, 0.65),
legend.direction = "horizontal"); xsite_cslowp
# Assemble a multi-panel figure!
cowplot::plot_grid(xsite_ntotp, xsite_nslowp, xsite_ctotp, xsite_cslowp,
labels = "AUTO", nrow = 2, ncol = 2)
# Export it
# ggsave(filename = file.path("graphs_CE_AM", "figure-1_across-sites.png"),
# width = 10, height = 10, units = "in")
```
```{r Site Average Graphs N and C verus NaOH and total}
# # N% ~ total P
# xsite_ntotp <- ggplot(data = site_n, aes(x = mean_total.P_conc_mg.kg, y = mean_N_conc_percent)) +
# # Error bars (defined above)
# n_se + totp_se +
# # Best fit line
# geom_smooth(method = "lm", formula = "y ~ x", se = F, color = "black") +
# # Points/labels for each dataset
# geom_point(aes(fill = lter, shape = dataset_num), size = 3, alpha = 0.95) +
# # Customizing theme elements
# labs(x = "Mean Total P (mg/kg) ± SE", y = "Mean N (%) ± SE",
# shape = "Dataset Number", fill = "LTER") +
# scale_shape_manual(values = data_shapes) +
# scale_fill_manual(values = lter_colors) +
# guides(fill = guide_legend(override.aes = list(shape = 21, size = 6)),
# shape = guide_legend(override.aes = list(size = 5))) +
# sparc_theme +
# theme(legend.position = "none"); xsite_ntotp
# N% ~ NaOH P
xsite_nNaOHp <- ggplot(data = site_n, aes(x = mean_NaOH.P_conc_mg.kg, y = mean_N_conc_percent)) +
# Error bars (defined above)
n_se + NaOH_se +
# Best fit line
geom_smooth(method = "lm", formula = "y ~ x", se = F, color = "black") +
# Points/labels for each dataset
geom_point(aes(fill = lter, shape = dataset_num), size = 3, alpha = 0.95) +
# Customizing theme elements
# Customizing theme elements
labs(x = "Mean NaOH P (mg/kg) ± SE", y = "Mean N (%) ± SE",
shape = "Dataset Number", fill = "LTER") +
scale_shape_manual(values = data_shapes) +
scale_fill_manual(values = lter_colors) +
sparc_theme +
guides(fill = F) +
sparc_theme +
theme(legend.position = c(0.4, 0.75),
legend.direction = "horizontal"); xsite_nNaOHp
# # C% ~ total P
# xsite_ctotp <- ggplot(data = site_c, aes(x = mean_total.P_conc_mg.kg, y = mean_C_conc_percent)) +
# # Error bars (defined above)
# c_se + totp_se +
# # Best fit line
# geom_smooth(method = "lm", formula = "y ~ x", se = F, color = "black") +
# # Points/labels for each dataset
# geom_point(aes(fill = lter, shape = dataset_num), size = 3, alpha = 0.95) +
# # Customizing theme elements
# labs(x = "Mean Total P (mg/kg) ± SE", y = "Mean C (%) ± SE",
# shape = "Dataset Number", fill = "LTER") +
# scale_shape_manual(values = data_shapes) +
# scale_fill_manual(values = lter_colors) +
# sparc_theme +
# guides(fill = F) +
# sparc_theme +
# theme(legend.position = c(0.4, 0.75),
# legend.direction = "horizontal"); xsite_ctotp
# C% ~ NaOH P
xsite_cNaOHp <- ggplot(data = site_c, aes(x = mean_NaOH.P_conc_mg.kg, y = mean_C_conc_percent)) +
# Error bars (defined above)
c_se + NaOH_se +
# Best fit line
geom_smooth(method = "lm", formula = "y ~ x", se = F, color = "black") +
# Points/labels for each dataset
geom_point(aes(fill = lter, shape = dataset_num), size = 3, alpha = 0.95) +
# Customizing theme elements
labs(x = "Mean NaOH P (mg/kg) ± SE", y = "Mean C (%) ± SE",
shape = "Dataset Number", fill = "LTER") +
scale_shape_manual(values = data_shapes) +
scale_fill_manual(values = lter_colors) +
guides(fill = guide_legend(override.aes = list(shape = 21, size = 6)),
shape = guide_legend(override.aes = list(size = 5))) +
guides(fill = guide_legend(override.aes = list(shape = 21, size = 6)),
shape = guide_legend(override.aes = list(size = 5))) +
guides(shape = F) +
sparc_theme +
theme(legend.position = c(0.6, 0.65),
legend.direction = "horizontal"); xsite_cslowp
# Assemble a multi-panel figure!
plot1 <- cowplot::plot_grid(xsite_cNaOHp, xsite_nNaOHp,
labels = "AUTO")
# xsite_ntotp,
# , nrow = 2, ncol = 2
# Export it
# ggsave(filename = file.path("graphs_CE_AM", "figure-1_across-sites.png"),
# width = 10, height = 10, units = "in")
```
```{r looking for where we're missing NaOH means}
subset <- which(is.na(site_df$mean_NaOH.P_conc_mg.kg))
missing <- site_df[subset,]
missing <- missing %>%
select(lter:site,mean_NaOH.P_conc_mg.kg,std.error_NaOH.P_conc_mg.kg)
```
```{r total C and N versus HCl/total}
# N % ~ HCl/total
xsite_nHClTotp <- ggplot(data = site_n, aes(x = HCl_Total_P, y = mean_N_conc_percent)) +
# Error bars (defined above)
# n_se + NaOH_se +
# Best fit line
geom_smooth(method = "lm", formula = "y ~ x", se = F, color = "black") +
# Points/labels for each dataset
geom_point(aes(fill = lter, shape = dataset_num), size = 3, alpha = 0.95) +
# Customizing theme elements
# Customizing theme elements
labs(x = "HCl / Total P", y = "Mean N (%) ± SE",
shape = "Dataset Number", fill = "LTER") +
scale_shape_manual(values = data_shapes) +
scale_fill_manual(values = lter_colors) +
sparc_theme +
guides(fill = F) +
sparc_theme +
theme(legend.position = c(0.4, 0.75),
legend.direction = "horizontal"); xsite_nHClTotp
# C% ~ HCl/total
xsite_cHClTotp <- ggplot(data = site_c, aes(x = HCl_Total_P, y = mean_C_conc_percent)) +
# Error bars (defined above)
# c_se + NaOH_se +
# Best fit line
geom_smooth(method = "lm", formula = "y ~ x", se = F, color = "black") +
# Points/labels for each dataset
geom_point(aes(fill = lter, shape = dataset_num), size = 3, alpha = 0.95) +
# Customizing theme elements
labs(x = "HCl / Total P", y = "Mean C (%) ± SE",
shape = "Dataset Number", fill = "LTER") +
scale_shape_manual(values = data_shapes) +
scale_fill_manual(values = lter_colors) +
guides(fill = guide_legend(override.aes = list(shape = 21, size = 6)),
shape = guide_legend(override.aes = list(size = 5))) +
guides(fill = guide_legend(override.aes = list(shape = 21, size = 6)),
shape = guide_legend(override.aes = list(size = 5))) +
guides(shape = F) +
sparc_theme +
theme(legend.position = c(0.6, 0.65),
legend.direction = "horizontal"); xsite_cHClTotp
# Assemble a multi-panel figure!
plot2 <- cowplot::plot_grid(xsite_nHClTotp, xsite_cHClTotp,
labels = "AUTO")
```
```{r Site Average Graphs slow versus total}
# # N% ~ total P
# xsite_ntotp <- ggplot(data = site_n, aes(x = mean_total.P_conc_mg.kg, y = mean_N_conc_percent)) +
# # Error bars (defined above)
# n_se + totp_se +
# # Best fit line
# geom_smooth(method = "lm", formula = "y ~ x", se = F, color = "black") +
# # Points/labels for each dataset
# geom_point(aes(fill = lter, shape = dataset_num), size = 3, alpha = 0.95) +
# # Customizing theme elements
# labs(x = "Mean Total P (mg/kg) ± SE", y = "Mean N (%) ± SE",
# shape = "Dataset Number", fill = "LTER") +
# scale_shape_manual(values = data_shapes) +
# scale_fill_manual(values = lter_colors) +
# guides(fill = guide_legend(override.aes = list(shape = 21, size = 6)),
# shape = guide_legend(override.aes = list(size = 5))) +
# sparc_theme +
# theme(legend.position = "none"); xsite_ntotp
# N% ~ NaOH P
xsite_HCL_Tot_p <- ggplot(data = site_n, aes(x = mean_slow.P_conc_mg.kg, y = mean_total.P_conc_mg.kg)) +
# Error bars (defined above)
# slowp_se + totp_se +
# Best fit line
geom_smooth(method = "lm", formula = "y ~ x", se = F, color = "black") +
# Points/labels for each dataset
geom_point(aes(fill = lter, shape = dataset_num), size = 3, alpha = 0.95) +
# Customizing theme elements
# Customizing theme elements
labs(x = "Mean Slow P (mg/kg) ± SE", y = "Mean Total P (mg/kg) ± SE",
shape = "Dataset Number", fill = "LTER") +
scale_shape_manual(values = data_shapes) +
scale_fill_manual(values = lter_colors) +
sparc_theme +
guides(fill = F) +
sparc_theme +
theme(legend.position = c(0.4, 0.75),
legend.direction = "horizontal"); xsite_HCL_Tot_p
# # C% ~ total P
# xsite_ctotp <- ggplot(data = site_c, aes(x = mean_total.P_conc_mg.kg, y = mean_C_conc_percent)) +
# # Error bars (defined above)
# c_se + totp_se +
# # Best fit line
# geom_smooth(method = "lm", formula = "y ~ x", se = F, color = "black") +
# # Points/labels for each dataset
# geom_point(aes(fill = lter, shape = dataset_num), size = 3, alpha = 0.95) +
# # Customizing theme elements
# labs(x = "Mean Total P (mg/kg) ± SE", y = "Mean C (%) ± SE",
# shape = "Dataset Number", fill = "LTER") +
# scale_shape_manual(values = data_shapes) +
# scale_fill_manual(values = lter_colors) +
# sparc_theme +
# guides(fill = F) +
# sparc_theme +
# theme(legend.position = c(0.4, 0.75),
# legend.direction = "horizontal"); xsite_ctotp
# C% ~ NaOH P
# xsite_cNaOHp <- ggplot(data = site_c, aes(x = mean_slow.P_conc_mg.kg, y = mean_C_conc_percent)) +
# # Error bars (defined above)
# c_se + NaOH_se +
# # Best fit line
# geom_smooth(method = "lm", formula = "y ~ x", se = F, color = "black") +
# # Points/labels for each dataset
# geom_point(aes(fill = lter, shape = dataset_num), size = 3, alpha = 0.95) +
# # Customizing theme elements
# labs(x = "Mean NaOH P (mg/kg) ± SE", y = "Mean C (%) ± SE",
# shape = "Dataset Number", fill = "LTER") +
# scale_shape_manual(values = data_shapes) +
# scale_fill_manual(values = lter_colors) +
# guides(fill = guide_legend(override.aes = list(shape = 21, size = 6)),
# shape = guide_legend(override.aes = list(size = 5))) +
# guides(fill = guide_legend(override.aes = list(shape = 21, size = 6)),
# shape = guide_legend(override.aes = list(size = 5))) +
# guides(shape = F) +
# sparc_theme +
# theme(legend.position = c(0.6, 0.65),
# legend.direction = "horizontal"); xsite_cslowp
# Assemble a multi-panel figure!
data3 <- cowplot::plot_grid(xsite_HCL_Tot_p,
labels = "AUTO")
# xsite_ntotp,
# , nrow = 2, ncol = 2
# Export it
# ggsave(filename = file.path("graphs_CE_AM", "figure-1_across-sites.png"),
# width = 10, height = 10, units = "in")
```