-
Notifications
You must be signed in to change notification settings - Fork 0
/
CraigPpgraphs.R
1568 lines (1242 loc) · 73 KB
/
CraigPpgraphs.R
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
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
## ------------------------------------------ ##
# Across-site and Within-site N and P relationships ----
## ------------------------------------------ ##
## ------------------------------------------ ##
# Housekeeping / Loading libraries and data -----
## ------------------------------------------ ##
# Load necessary libraries
library(Rmisc)
library(ggplot2)
library(dplyr)
library(MuMIn)
library(sjPlot)
library(tidyverse)
# loading stats ready data from google drive
# install.packages("librarian")
librarian::shelf(tidyverse, googledrive, supportR)
# Create necessary sub-folder(s)
dir.create(path = file.path("data", "tidy_data"), showWarnings = F)
dir.create(path = file.path("data", "stats_ready"), showWarnings = F)
# Clear environment
rm(list = ls())
# Identify needed tidy file(s)
tidy_drive <- googledrive::as_id("https://drive.google.com/drive/u/0/folders/1pjgN-wRlec65NDLBvryibifyx6k9Iqy9")
# Identify the archival data in that folder and download it
googledrive::drive_ls(path = tidy_drive) %>%
dplyr::filter(name == "sparc-soil-p_full-plus-ancil-and-spatial.csv") %>%
googledrive::drive_download(file = .$id, overwrite = T,
path = file.path("data", "tidy_data", .$name))
# Read that file in
cores <- read.csv(file = file.path("data", "stats_ready",
"sparc-soil-p_stats-ready_mineral_0-10.csv"))
# Subset data to konza 1
# not sure we want/need to do this anymore, hashtagging it out for now - EV 10/08
# JK this code makes it so that the three sites withing the Konza 1 dataset show up as their own datasets
cores$dataset <- ifelse(cores$dataset == "Konza_1", cores$site, cores$dataset )
cores <- cores %>%
mutate(PropSlowTotal = slow.P_conc_mg.kg/total.P_conc_mg.kg)
# Double checking all sites exist for slow P dataset here that shouls before subset code below
# Adding code to subset to only observations where both slow P and total N values exist for Niwot 1
# Hashtag out to make total P figure (come back and make separate dataset later)
cores$slow.P_conc_mg.kg <- ifelse(cores$dataset == "Niwot_1" & is.na(cores$N_conc_percent) == TRUE, NA, cores$slow.P_conc_mg.kg)
cores$N_conc_percent <- ifelse(cores$dataset == "Niwot_1" & is.na(cores$slow.P_conc_mg.kg) == TRUE, NA, cores$N_conc_percent)
## ------------------------------------------ ##
# Making summary datasets -----
## ------------------------------------------ ##
# create a data frame that contains the number of rows with which we have sites
Final_table<-data.frame(matrix(nrow=length(unique(cores$dataset)),ncol=1))
names(Final_table) <- c('dataset')
Final_table$dataset<-unique(cores$dataset)
# PLOT LEVEL DATASETS
## TOTAL P
# plot_totalP <-aggregate(cbind(N_conc_percent,total.P_conc_mg.kg,PropSlowTotal)~dataset+site+block+plot,mean, data=cores, na.rm=T)
plot_totalP <- cores %>%
dplyr::group_by(dataset,site,block,plot) %>%
dplyr::summarise(N_conc_percent = mean(N_conc_percent),
total.P_conc_mg.kg = mean(total.P_conc_mg.kg),
mean.annual.precip_mm = mean(mean.annual.precip_mm),
PropSlowTotal = mean(PropSlowTotal) )
## SLOW P
# plot_slowP<-aggregate(cbind(N_conc_percent,slow.P_conc_mg.kg,PropSlowTotal)~dataset+site+block+plot, mean, data=cores, na.rm = F)
plot_slowP <- cores %>%
dplyr::group_by(dataset,site,block,plot) %>%
dplyr::summarise(N_conc_percent = mean(N_conc_percent),
slow.P_conc_mg.kg = mean(slow.P_conc_mg.kg),
PropSlowTotal = mean(PropSlowTotal) )
# SITE LEVEL DATASETS
## TOTAL P
# site_totalP<-aggregate(cbind(N_conc_percent,total.P_conc_mg.kg,PropSlowTotal)~dataset+site,mean, data=plot_totalP,na.rm=T) # changing data to plot slow P - this means the site means is the mean of the plot means
site_totalP <- plot_totalP %>%
dplyr::group_by(dataset,site) %>%
dplyr::summarise(N_conc_percent = mean(N_conc_percent),
total.P_conc_mg.kg = mean(total.P_conc_mg.kg),
mean.annual.precip_mm = mean(mean.annual.precip_mm),
PropSlowTotal = mean(PropSlowTotal) )
## SLOW P
# site_slowP<-aggregate(cbind(N_conc_percent,slow.P_conc_mg.kg,PropSlowTotal)~dataset+site,mean, data=plot_slowP,na.rm=T)
site_slowP <- plot_slowP %>%
dplyr::group_by(dataset,site) %>%
dplyr::summarise(N_conc_percent = mean(N_conc_percent),
slow.P_conc_mg.kg = mean(slow.P_conc_mg.kg),
PropSlowTotal = mean(PropSlowTotal) )
# checking how many sites we have per dataset
table(site_slowP$dataset)
## SLOW P SUMMARIZED AND SITE SELECTED DATASETS
# Grouping site Slow P dataset by DATASET and adding columns for mean, standard deviation and standard error for N and P
dataset_means_slowP <- site_slowP %>%
dplyr::select(dataset,N_conc_percent,slow.P_conc_mg.kg,PropSlowTotal) %>%
dplyr::group_by(dataset) %>%
dplyr::summarise(mean_N = mean(N_conc_percent, na.rm = TRUE),
mean_P = mean(slow.P_conc_mg.kg, na.rm = TRUE),
mean_ratio = mean(PropSlowTotal, na.rm = TRUE),
sd_N = sd(N_conc_percent, na.rm = TRUE),
sd_P = sd(slow.P_conc_mg.kg, na.rm = TRUE),
sd_ratio = sd(PropSlowTotal, na.rm = TRUE),
se_N = plotrix::std.error(N_conc_percent, na.rm = TRUE),
se_P = plotrix::std.error(slow.P_conc_mg.kg, na.rm = TRUE) )
## SELECTING ONLY THE SITES WHERE WE HAVE SLOW P (AND REMOVING FCE AND TOOLIK 1)
dataset_means_slowP <- dataset_means_slowP %>%
filter(dataset %in% c("Calhoun","Niwot_1","Sevilleta_1","Coweeta","Hubbard Brook","Luquillo_2","Niwot_2","Konza_1","HJ_Andrews_1","CedarCreek","Jornada_2","Luquillo_3","Tapajos","Niwot_5","Konza_2","Smokey Valley","Hays","Arikaree") )
# MANUALLY CHANGING SEV 1 TOTAL N MEAN FOR NOW, NEED TO DISCUSS WITH ANNE FINAL SOLUTION
# Sev total N mean of grasslands and shrub sites from Anne's thesis = 0.055
dataset_means_slowP <- dataset_means_slowP %>%
mutate(mean_N = ifelse(dataset == "Sevilleta_1",0.055,mean_N))
# Grouping site Slow P dataset by SITE and adding columns for mean, standard deviation and standard error for N and P
site_means_slowP <- site_slowP %>%
select(dataset,site,N_conc_percent,slow.P_conc_mg.kg) %>%
group_by(dataset,site) %>%
dplyr::summarise(mean_N = mean(N_conc_percent, na.rm = TRUE),
mean_P = mean(slow.P_conc_mg.kg, na.rm = TRUE),
sd_N = sd(N_conc_percent, na.rm = TRUE),
sd_P = sd(slow.P_conc_mg.kg, na.rm = TRUE),
se_N = plotrix::std.error(N_conc_percent, na.rm = TRUE),
se_P = plotrix::std.error(slow.P_conc_mg.kg, na.rm = TRUE))
site_means_slowP <- site_means_slowP %>%
filter(dataset %in% c("Calhoun","Niwot_1","Sevilleta_1","Coweeta","Hubbard Brook","Luquillo_2","Niwot_2","Konza_1","HJ_Andrews_1","CedarCreek","Jornada_2","Luquillo_3","Tapajos","Niwot_5","Konza_2","Smokey Valley","Hays","Arikaree") )
site_means_slowP <- site_means_slowP %>%
mutate(mean_N = ifelse(dataset == "Sevilleta_1",0.055,mean_N))
## TOTAL P SUMMARIZED AND SITE SELECTED DATASETS
dataset_means_totalP <- site_totalP %>%
dplyr::select(dataset, N_conc_percent, total.P_conc_mg.kg, PropSlowTotal, mean.annual.precip_mm) %>%
group_by(dataset) %>%
dplyr::summarise(mean_N = mean(N_conc_percent, na.rm = TRUE),
mean_P = mean(total.P_conc_mg.kg, na.rm = TRUE),
mean_precip = mean(mean.annual.precip_mm, na.rm = TRUE),
mean_ratio = mean(PropSlowTotal, na.rm = TRUE),
sd_N = sd(N_conc_percent, na.rm = TRUE),
sd_P = sd(total.P_conc_mg.kg, na.rm = TRUE),
sd_ratio = sd(PropSlowTotal, na.rm = TRUE),
se_N = plotrix::std.error(N_conc_percent, na.rm = TRUE),
se_P = plotrix::std.error(total.P_conc_mg.kg, na.rm = TRUE))
# selecting all sites with full total P info
dataset_means_totalP <- dataset_means_totalP %>%
filter(dataset %in% c("Calhoun","Niwot_1","Sevilleta_1","Coweeta","Bonanza Creek_1","Hubbard Brook","Luquillo_1","Luquillo_2","Brazil_SouthernAmazon","Brazil_AtlanticForest","Jornada_1","Bonanza Creek_2","Sevilleta_2","Niwot_2","Niwot_3","Niwot_4","Toolik_1","Kellogg_Bio_Station","Konza_1","HJAndrews_1","CedarCreek","ChichaquaBottoms","Jornada_2","Toolik_2","Bonanza Creek_3","Luquillo_3","Tapajos","Niwot_5","Konza_2","Smokey Valley","Hays","Arikaree") )
# MANUALLY CHANGING SEV 1 TOTAL N MEAN FOR NOW, NEED TO DISCUSS WITH ANNE FINAL SOLUTION
# Sev total N mean of grasslands and shrub sites from Anne's thesis = 0.055
dataset_means_totalP <- dataset_means_totalP %>%
mutate(mean_N = ifelse(dataset == "Sevilleta_1",0.055,mean_N))
site_means_totalP <- site_totalP %>%
select(dataset,site,N_conc_percent,total.P_conc_mg.kg) %>%
group_by(dataset,site) %>%
dplyr::summarise(mean_N = mean(N_conc_percent, na.rm = TRUE),mean_P = mean(total.P_conc_mg.kg, na.rm = TRUE),sd_N = sd(N_conc_percent, na.rm = TRUE),sd_P = sd(total.P_conc_mg.kg, na.rm = TRUE),se_N = plotrix::std.error(N_conc_percent, na.rm = TRUE),se_P = plotrix::std.error(total.P_conc_mg.kg, na.rm = TRUE))
# selecting all sites with full total P info
site_means_totalP <- site_means_totalP %>%
filter(dataset %in% c("Calhoun","Niwot_1","Sevilleta_1","Coweeta","Bonanza Creek_1","Hubbard Brook","Luquillo_1","Luquillo_2","Brazil_SouthernAmazon","Brazil_AtlanticForest","Jornada_1","Bonanza Creek_2","Sevilleta_2","Niwot_2","Niwot_3","Niwot_4","Toolik_1","Kellogg_Bio_Station","Konza_1","HJAndrews_1","CedarCreek","ChichaquaBottoms","Jornada_2","Toolik_2","Bonanza Creek_3","Luquillo_3","Tapajos","Niwot_5","Konza_2","Smokey Valley","Hays","Arikaree") )
## ------------------------------------------ ##
# SIMPLE LINEAR REGRESSIONS AND EXPONENTIAL DECAY MODEL FOR CROSS-SITE ANALYSES FOR SLOW AND TOTAL P -----
## ------------------------------------------ ##
### SLOW P ANALYSES
## MAKING FIGURES
# library(MASS) # to access Animals data sets
# library(scales) # to access break formatting functions
dataset_means_slowP <- dataset_means_slowP %>%
mutate(log_mean_N = log(mean_N) )
# Renaming datasets to remomve underscores
dataset_means_slowP <- dataset_means_slowP %>%
mutate(dataset = recode(dataset,
Jornada_2 = "Jornada (2)",
Luquillo_1= "Luquillo (1)",
Luquillo_2 = "Luquillo (2)",
Luquillo_3 = "Luquillo (3)",
Niwot_1 = "Niwot (1)",
Niwot_2 = "Niwot (2)",
Niwot_5 = "Niwot (5)",
Konza_2 = "Konza (2)",
Sevilleta_1 = "Sevilleta (1)"))
# %>%
# rename('Ratio of Slow P over Total P' = mean_ratio)
library(ggrepel)
TotalN_SlowPfig_dataset <- ggplot(data = dataset_means_slowP,
aes(x=mean_P, y=mean_N) ) +
geom_point(aes(color = mean_ratio), size=3) + # removing se size for now
labs(title = "Slow P versus Total N",
y = "Total N (%)") +
xlab(bquote(Slow~P~(mg~kg^-1))) +
geom_label_repel(data = dataset_means_slowP,
aes(label = dataset), nudge_x=0.45, nudge_y=0.025,
arrow=NULL) +
stat_smooth(method = 'lm', se = TRUE, color = "black") +
theme_bw() +
scale_color_gradientn(colours = rainbow(5)) +
labs(color = "Ratio of Slow P to Total P") +
theme(
plot.title = element_text(size = 20), # Title text size
axis.title.x = element_text(size = 14), # X-axis title text size
axis.title.y = element_text(size = 14), # Y-axis title text size
axis.text.x = element_text(size = 12), # X-axis text size
axis.text.y = element_text(size = 12), # Y-axis text size
legend.title = element_text(size = 14), # Legend title text size
legend.text = element_text(size = 12) # Legend text size
)
ggsave(plot = TotalN_SlowPfig_dataset, filename = "figures/TotalN_SlowPfig_dataset.png", width = 15, height = 10)
dataset_means_totalP <- dataset_means_totalP %>%
mutate(dataset = recode(dataset,
Jornada_2 = "Jornada (2)",
# Luquillo_1= "Luquillo (1)",
Luquillo_2 = "Luquillo (2)",
# Luquillo_3 = "Luquillo (3)",
Niwot_1 = "Niwot (1)",
# Niwot_2 = "Niwot (2)",
Niwot_5 = "Niwot (5)",
Konza_2 = "Konza (2)",
Sevilleta_1 = "Sevilleta (1)"))
TotalN_TotalPfig_dataset_log <- ggplot(data = dataset_means_totalP,
aes(x=mean_P, y=mean_N) ) +
geom_point(aes(color=dataset), size=3) + # removing se size for now
labs(title = "Total P versus Total N (Log transformed)",
y = "Total N (%)") +
xlab(bquote(Total~P~(mg~kg^-1))) +
geom_label_repel(data = dataset_means_totalP,
aes(label = dataset), nudge_x=0.45, nudge_y=0.025,
arrow=NULL, max.overlaps = 20) +
stat_smooth(method = 'lm', se = TRUE, color = "black") +
theme_bw() +
theme(
plot.title = element_text(size = 20), # Title text size
axis.title.x = element_text(size = 14), # X-axis title text size
axis.title.y = element_text(size = 14), # Y-axis title text size
axis.text.x = element_text(size = 12), # X-axis text size
axis.text.y = element_text(size = 12), # Y-axis text size
legend.title = element_text(size = 14), # Legend title text size
legend.text = element_text(size = 12) # Legend text size
) +
labs(color = "Dataset") +
scale_x_log10() +
scale_y_log10()
ggsave(plot = TotalN_TotalPfig_dataset_log, filename = "figures/TotalN_TotalPfig_dataset_logged.png", width = 15, height = 10)
# ggsave(plot = TotalN_TotalPfig_dataset, filename = "figures/TotalN_TotalPfig_dataset.png", width = 15, height = 10)
test <- subset(dataset_means_slowP, dataset == "Niwot (1)" | dataset == "Niwot (2)" | dataset == "Niwot (5)" )
# figure with just Niwot sites on it
Niwot_sites <- ggplot(data = subset(dataset_means_slowP, dataset == "Niwot (1)" | dataset == "Niwot (2)" | dataset == "Niwot (5)" ),aes(x=mean_P, y=mean_N) ) +
geom_point(aes(color = mean_ratio), size=3) + # removing se size for now
labs(title = "Slow P versus Total N",
y = "Total N (%)") +
xlab(bquote(Slow~P~(mg~kg^-1))) +
geom_label_repel(data = dataset_means_slowP,
aes(label = dataset), nudge_x=0.45, nudge_y=0.025,
arrow=NULL) +
stat_smooth(method = 'lm', se = TRUE, color = "black") +
theme_bw() +
scale_color_gradientn(colours = rainbow(5)) +
labs(color = "Ratio of Slow P to Total P") +
theme(
plot.title = element_text(size = 20), # Title text size
axis.title.x = element_text(size = 14), # X-axis title text size
axis.title.y = element_text(size = 14), # Y-axis title text size
axis.text.x = element_text(size = 12), # X-axis text size
axis.text.y = element_text(size = 12), # Y-axis text size
legend.title = element_text(size = 14), # Legend title text size
legend.text = element_text(size = 12) # Legend text size
)
ggsave(plot = Niwot_sites, filename = "figures/TotalN_SlowPfig_Niwot_sites.png", width = 15, height = 10)
comb <- cowplot::plot_grid(TotalN_TotalPfig_dataset,TotalN_SlowPfig_dataset)
# controls_y_FIXED <- cowplot::plot_grid(group1_fig_F, group2_fig_F, group3_fig_F, group4_fig_F)
ggsave(plot = comb, filename = "figures/Figure_1.png", width = 25, height = 10)
SlowPfig_dataset2 <- ggplot(data = subset(dataset_means_slowP, dataset != "Niwot_5"),
aes(x=mean_ratio, y=mean_N) ) +
geom_point(aes(color = dataset), ) + # removing se size for now
labs(title = "Slow P versus Total N by Dataset",
x = "Ratio of Slow P over Total P",
y = "Total N %") +
geom_text_repel(data = subset(dataset_means_slowP, dataset != "Niwot_5"),
aes(label = dataset), nudge_x=0.05, nudge_y=0.01,
check_overlap=T) +
stat_smooth(method = 'lm', se = TRUE, color = "black") +
theme_bw()
ratio_dataset_lm <- lm(mean_N ~ mean_ratio, data = dataset_means_slowP)
summary(ratio_dataset_lm)
tab_model(ratio_dataset_lm)
# +
# scale_color_gradientn(colours = rainbow(5))
# data = subset(dataset_means_slowP, dataset != "Niwot_5")
# +
# scale_y_log10(breaks = trans_breaks("log10", function(x) 10^x),
# labels = trans_format("log10", math_format(10^.x)))
# +
# scale_y_log10(breaks = trans_breaks("log10", function(x) 10^x) )
ggsave(plot = SlowPfig_dataset, filename = "figures/SlowP_TotalN_datasets_woNWT5.png", width = 10, height = 8)
SlowPfig_site <- ggplot(data = site_means_slowP, aes(x=mean_P, y=mean_N, color = dataset) ) +
geom_point() + #size = 1/se_P removing se size for now
labs(title = "Slow P versus Total N by Site",
x = "Slow P mg/kg",
y = "Total N %") +
geom_text(data = site_means_slowP, aes(label = dataset), nudge_x=0.45, nudge_y=0.025,
check_overlap=T) +
stat_smooth(method = 'lm', se = TRUE, color = "black") +
theme_bw()
ggsave(plot = SlowPfig_site, filename = "figures/SlowP_TotalN_sites.png", width = 7, height = 4)
## RUNNING MODELS
# Slow P modeling with SITE averages # p-value: 0.8663
SlowP_site_lm <- lm(mean_N ~ mean_P, data = site_means_slowP)
summary(SlowP_site_lm)
tab_model(SlowP_site_lm)
# Slow P modeling with DATASET averages
# Simple linear model# = p-value: 0.1401
# woah p-value went way up after the edit to SEV, p-value: 0.8467
# after manually updating Sev1 mean p-value: 0.128
SlowP_dataset_lm <- lm(mean_N ~ mean_P, data = dataset_means_slowP)
summary(SlowP_dataset_lm)
tab_model(SlowP_dataset_lm)
# running model without Niwot 5
SlowP_dataset_lm_woNWT5 <- lm(mean_N ~ mean_P, data = subset(dataset_means_slowP, dataset != "Niwot_5"))
summary(SlowP_dataset_lm_woNWT5)
tab_model(SlowP_dataset_lm_woNWT5)
# Log-log transformed linear model # p-value: 0.2318
# After editing, SEV p-value: 0.818
SlowP_dataset_lm_log <- lm(log(mean_N) ~ mean_P, data = dataset_means_slowP)
summary(SlowP_dataset_lm_log)
tab_model(SlowP_dataset_lm_log)
# , weights = 1/se_P
## Exponential decay models
# After editing, SEV p-value: 0.3
# Hmm not sure if this is working well anymore after adding the SEV data
SlowP_dataset_ExpDec <- nls(mean_N ~ exp(-k*mean_P), start = list(k=0.5), data = dataset_means_slowP)
summary(SlowP_dataset_ExpDec)
tab_model(SlowP_dataset_ExpDec)
# Adding model fit line to figure
SlowPfig_dataset <- SlowPfig_dataset +
stat_smooth(method = 'nls',
method.args = list(start = c(a=-0.4096, b=0.005)),
formula = y~a*exp(b*x), colour = 'black', linetype="dashed", se = FALSE) +
theme_minimal()
### Running dataset model making Luquillo means zero
dataset_means_slowP_LUQ_Zero <- dataset_means_slowP
dataset_means_slowP_LUQ_Zero$mean_P <- ifelse(dataset_means_slowP_LUQ_Zero$dataset == "Luquillo_1",0.00001,dataset_means_slowP_LUQ_Zero$mean_P)
dataset_means_slowP_LUQ_Zero$mean_P <- ifelse(dataset_means_slowP_LUQ_Zero$dataset == "Luquillo_2",0.00001,dataset_means_slowP_LUQ_Zero$mean_P)
model_params <- dataset_means_slowP_LUQ_Zero %>% # save the regression line yhat points
mutate(fit=fitted(SlowP_dataset_lm_LUQ0))
# slow P fig with Luquillo being 0.00001
SlowPfig_dataset_LUQZERO <- ggplot(data = dataset_means_slowP_LUQ_Zero, aes(x=mean_P, y=mean_N, color = dataset) ) +
geom_point() + # removing se size for now
labs(title = "Slow Phosphorus versus Total Nitrogen by Dataset",
x = "Slow P mg/kg",
y = "Total N %") +
geom_text(data = dataset_means_slowP_LUQ_Zero, aes(label = dataset), nudge_x=0.45, nudge_y=0.025,
check_overlap=T) +
theme_minimal() +
geom_line(data = model_params, aes(y=fit), color='blue')
# stat_smooth(method = 'lm',
# method.args = list(start = c(m=-0.02, b=0.005)),
# formula = mean_N~m*log(mean_P)+b, colour = 'black', linetype="dashed", se = FALSE, data = dataset_means_slowP_LUQ_Zero)
# # stat_smooth(method = 'nls',
# method.args = list(start = c(a=-0.4096, b=0.005)),
# formula = y~a*exp(b*x), colour = 'black', linetype="dashed", se = FALSE) +
# fig and model
SlowPfig_dataset_Luqillo_zero <- ggplot(data = dataset_means_slowP_LUQ_Zero, aes(x=mean_P, y=mean_N, color = dataset) ) +
geom_point() + # removing se size for now
labs(title = "Slow P versus Total N by Dataset",
x = "Slow P mg/kg",
y = "Total N %") +
geom_text(data = dataset_means_slowP_LUQ_Zero, aes(label = dataset), nudge_x=0.45, nudge_y=0.025,
check_overlap=T) +
theme_minimal()
# Simple linear model # = p-value: 0.1078
SlowP_dataset_lm_LUQ0 <- lm(mean_N ~ log(mean_P), data = dataset_means_slowP_LUQ_Zero)
summary(SlowP_dataset_lm_LUQ0)
tab_model(SlowP_dataset_lm_LUQ0)
## Exponential decay models p-value = 0.11
SlowP_dataset_ExpDec_LUQ0 <- nls(mean_N ~ exp(-k*mean_P), start = list(k=0.5), data = dataset_means_slowP_LUQ_Zero)
summary(SlowP_dataset_ExpDec_LUQ0)
tab_model(SlowP_dataset_ExpDec_LUQ0)
AIC(SlowP_dataset_lm_LUQ0,SlowP_dataset_ExpDec_LUQ0)
### Running site model making Luquillo means zero
site_means_slowP_LUQ_Zero <- site_means_slowP
site_means_slowP_LUQ_Zero$mean_P <- ifelse(site_means_slowP_LUQ_Zero$dataset == "Luquillo_1",0.00001,site_means_slowP_LUQ_Zero$mean_P)
site_means_slowP_LUQ_Zero$mean_P <- ifelse(site_means_slowP_LUQ_Zero$dataset == "Luquillo_2",0.00001,site_means_slowP_LUQ_Zero$mean_P)
SlowPfig_site_Luqillo_zero <- ggplot(data = site_means_slowP_LUQ_Zero, aes(x=mean_P, y=mean_N, color = dataset) ) +
geom_point() + #size = 1/se_P removing se size for now
labs(title = "Slow P versus Total N by Site",
x = "Slow P mg/kg",
y = "Total N %") +
geom_text(data = site_means_slowP_LUQ_Zero, aes(label = dataset), nudge_x=0.45, nudge_y=0.025,
check_overlap=T) +
theme_minimal()
### TOTAL P ANALYSES
## MAKING FIGURES
TotalPfig_dataset <- ggplot(data = dataset_means_totalP, aes(x=mean_P, y=mean_N) ) +
geom_point(aes(color = dataset)) + # removing se size for now
# geom_smooth(method=lm, se=TRUE, color = "black") +
labs(title = "Total P versus Total N by Dataset",
x = "Total P mg/kg",
y = "Total N %") +
geom_text(data = dataset_means_totalP, aes(label = dataset,color = dataset), nudge_x=0.45, nudge_y=0.025,
check_overlap=T) +
theme_bw()
ggsave(plot = TotalPfig_dataset, filename = "figures/TotalP_TotalN_datasets.png", width = 7, height = 4)
TotalPfig_site <- ggplot(data = site_means_totalP, aes(x=mean_P, y=mean_N, color = dataset) ) +
geom_point() + #size = 1/se_P removing se size for now +
geom_smooth(method=lm, se=FALSE, color = "black") +
labs(title = "Total P versus Total N by Site",
x = "Total P mg/kg",
y = "Total N %") +
geom_text(data = site_means_totalP, aes(label = dataset), nudge_x=0.45, nudge_y=0.025,
check_overlap=T) +
theme_minimal()
## RUNNING MODELS
# Total P modeling with SITE
# After fixing SEV, p-value: 6.301e-06
TotalP_site_lm <- lm(mean_N ~ mean_P, data = site_means_totalP)
summary(TotalP_site_lm)
tab_model(TotalP_site_lm)
# Slow P modeling with DATASET averages
# Simple linear model
# After fixing SEV, p-value: p-value: 0.03679
TotalP_dataset_lm <- lm(mean_N ~ mean_P, data = dataset_means_totalP)
summary(TotalP_dataset_lm)
tab_model(TotalP_dataset_lm)
# Log-log transformed linear model
TotalP_dataset_lm_log <- lm(log(mean_N) ~ log(mean_P), data = dataset_means_totalP)
summary(TotalP_dataset_lm_log)
tab_model(TotalP_dataset_lm_log)
# , weights = 1/se_P
# THIS MODEL FIT DOESN'T REALLY MAKE SENSE ANYMORE
## Exponential decay models
# TotalP_dataset_ExpDec <- nls(mean_N ~ exp(-k*mean_P), start = list(k=0.4096), data = dataset_means_totalP)
# summary(TotalP_dataset_ExpDec)
# tab_model(TotalP_dataset_ExpDec)
#
# # Adding model fit line to figure
# SlowPfig_dataset <- SlowPfig_dataset +
# stat_smooth(method = 'nls',
# method.args = list(start = c(a=-0.4096, b=0.005)),
# formula = y~a*exp(b*x), colour = 'black', linetype="dashed", se = FALSE) +
# theme_minimal()
## ------------------------------------------ ##
# Moving previous code down here that we don't need for now 5/12/24 EV -----
## ------------------------------------------ ##
# SIMPLE LINEAR REGRESSIONS BY SITE OF TOTAL P VS TOTAL N
# This code produces a summary table with the slope and p-value for each dataset,doing a simple linear model
# Write 1-2 sentences in results section just summarizing this table (put table in appendix and reference)
sum_table<-data.frame(matrix(nrow=length(unique(cores$dataset)),ncol=3))
names(sum_table) <- c('dataset', 'Total_P.N_slope', 'Total_P.N_.pvalue')
cores_totalP<-cores
cores_totalP<-subset(cores_totalP,is.na(total.P_conc_mg.kg)==F) # keep rows where total P is not not na
cores_totalP<-subset(cores_totalP,is.na(N_conc_percent)==F) # same for total N
cores_totalP<-subset(cores_totalP,lter!="CDR")#remove CDR because only 1 observation
cores_totalP<-subset(cores_totalP,dataset!="Konza_2")#remove Konza_2 because only 1 observation
cores_totalP<-subset(cores_totalP,dataset!="Toolik_1")# Total P showing up as zero but should be NA
cores_totalP$set<-as.numeric(as.factor(cores_totalP$dataset)) # produces table with only observations that have both total P and total N
# for loop subsets by dataset and produces the summary of an lm for each dataset, pulls parameters from summary and includes in table for each site
for(i in 1:max(cores_totalP$set)){
a<-subset(cores_totalP,set==i)
b<-summary(lm(N_conc_percent~total.P_conc_mg.kg,data = a))
sum_table[i,1]<-first(a$dataset)
sum_table[i,2]<-b$coefficients[2,1]
sum_table[i,3]<-b$coefficients[2,4]
}
Final_table<-merge(Final_table,sum_table,all.x = T) # merging the looped product table with final table that has all possible datasets in our study
# SIMPLE LINEAR REGRESSIONS BY SITE OF SLOW P VS TOTAL N
#
sum_table<-data.frame(matrix(nrow=length(unique(cores$dataset)),ncol=3))
names(sum_table) <- c('dataset', 'Slow_P.N_slope', 'Slow_P.N_.pvalue')
cores_SlowP<-cores
cores_SlowP<-subset(cores_SlowP,is.na(slow.P_conc_mg.kg)==F)
cores_SlowP<-subset(cores_SlowP,is.na(N_conc_percent)==F)
cores_SlowP<-subset(cores_SlowP,lter!="CDR")#remove CDR because only 1 observation
cores_SlowP<-subset(cores_SlowP,dataset!="Konza_2")#remove Konza_2 because only 1 observation
cores_SlowP<-subset(cores_SlowP,dataset!="Niwot_5")# Slow P same values for all 3 observations
cores_SlowP$set<-as.numeric(as.factor(cores_SlowP$dataset))
for(i in 1:max(cores_SlowP$set)){
a<-subset(cores_SlowP,set==i)
b<-summary(lm(N_conc_percent~slow.P_conc_mg.kg,data = a))
sum_table[i,1]<-first(a$dataset)
sum_table[i,2]<-b$coefficients[2,1]
sum_table[i,3]<-b$coefficients[2,4]
}
Final_table<-merge(Final_table,sum_table,all.x = T)
sum_table<-data.frame(matrix(nrow=length(unique(cores$dataset)),ncol=3))
names(sum_table) <- c('dataset', 'Total_P.N_slope_Plot', 'Total_P.N_.pvalue_Plot')
# plot_totalP<-cores
plot_totalP<-subset(plot_totalP,is.na(total.P_conc_mg.kg)==F)
plot_totalP<-subset(plot_totalP,is.na(N_conc_percent)==F)
plot_totalP<-subset(plot_totalP,lter!="CDR")#remove CDR because only 1 observation
plot_totalP<-subset(plot_totalP,dataset!="Konza_2")#remove Konza_2 because only 1 observation
plot_totalP<-subset(plot_totalP,dataset!="Toolik_1")# Total P showing up as zero but should be NA
plot_totalP$set<-as.numeric(as.factor(plot_totalP$dataset))
for(i in 1:max(plot_totalP$set)){
a<-subset(plot_totalP,set==i)
b<-summary(lm(N_conc_percent~total.P_conc_mg.kg,data = a))
sum_table[i,1]<-first(a$dataset)
sum_table[i,2]<-b$coefficients[2,1]
sum_table[i,3]<-b$coefficients[2,4]
}
Final_table<-merge(Final_table,sum_table,all.x = T)
sum_table<-data.frame(matrix(nrow=length(unique(cores$dataset)),ncol=3))
names(sum_table) <- c('dataset', 'Slow_P.N_slope_Plot', 'Slow_P.N_.pvalue_Plot')
plot_slowP<-subset(plot_slowP,is.na(slow.P_conc_mg.kg)==F)
plot_slowP<-subset(plot_slowP,is.na(N_conc_percent)==F)
plot_slowP<-subset(plot_slowP,dataset!="CedarCreek_1")#remove CDR because only 1 observation
plot_slowP<-subset(plot_slowP,dataset!="Konza_2")#remove Konza_2 because only 1 observation
plot_slowP<-subset(plot_slowP,dataset!="Niwot_5")#
plot_slowP$set<-as.numeric(as.factor(plot_slowP$dataset))
for(i in 1:max(plot_slowP$set)){
a<-subset(plot_slowP,set==i)
b<-summary(lm(N_conc_percent~slow.P_conc_mg.kg,data = a))
sum_table[i,1]<-first(a$dataset)
sum_table[i,2]<-b$coefficients[2,1]
sum_table[i,3]<-b$coefficients[2,4]
}
Final_table<-merge(Final_table,sum_table,all.x = T)
sum_table<-data.frame(matrix(nrow=length(unique(cores$dataset)),ncol=3))
names(sum_table) <- c('dataset', 'Total_P.N_slope_site', 'Total_P.N_.pvalue_site')
site_totalP<-subset(site_totalP,is.na(total.P_conc_mg.kg)==F)
site_totalP<-subset(site_totalP,is.na(N_conc_percent)==F)
site_totalP<-subset(site_totalP,dataset!="CedarCreek_1")#remove CDR because only 1 observation
site_totalP<-subset(site_totalP,dataset!="CedarCreek_2")#remove CDR because only 1 observation
site_totalP<-subset(site_totalP,dataset!="Konza_2")#remove Konza_2 because only 1 observation
site_totalP<-subset(site_totalP,dataset!="Toolik_1")# Total P showing up as zero but should be NA
site_totalP<-subset(site_totalP,dataset!="Niwot_3")# Total P showing up as zero but should be NA
site_totalP<-subset(site_totalP,dataset!="Niwot_4")# Total P showing up as zero but should be NA
site_totalP$set<-as.numeric(as.factor(site_totalP$dataset))
for(i in 1:max(site_totalP$set)){
a<-subset(site_totalP,set==i)
b<-summary(lm(N_conc_percent~total.P_conc_mg.kg,data = a))
sum_table[i,1]<-first(a$dataset)
sum_table[i,2]<-b$coefficients[2,1]
sum_table[i,3]<-b$coefficients[2,4]
}
Final_table<-merge(Final_table,sum_table,all.x = T)
sum_table<-data.frame(matrix(nrow=length(unique(cores$dataset)),ncol=3))
names(sum_table) <- c('dataset', 'Slow_P.N_slope_site', 'Slow_P.N_.pvalue_site')
site_slowP<-subset(site_slowP,is.na(slow.P_conc_mg.kg)==F)
site_slowP<-subset(site_slowP,is.na(N_conc_percent)==F)
site_slowP<-subset(site_slowP,dataset!="CedarCreek_1")#remove CDR because only 1 observation
site_slowP<-subset(site_slowP,dataset!="Konza_2")#remove Konza_2 because only 1 observation
site_slowP<-subset(site_slowP,dataset!="Niwot_5")#
site_slowP$set<-as.numeric(as.factor(site_slowP$dataset))
for(i in 1:max(site_slowP$set)){
a<-subset(site_slowP,set==i)
b<-summary(lm(N_conc_percent~slow.P_conc_mg.kg,data = a))
sum_table[i,1]<-first(a$dataset)
sum_table[i,2]<-b$coefficients[2,1]
sum_table[i,3]<-b$coefficients[2,4]
}
Final_table<-merge(Final_table,sum_table,all.x = T)
# LOWERING CODE WE DONT NEED FOR NOW
# mean
dataset_slowP_mean <- aggregate(cbind(N_conc_percent,slow.P_conc_mg.kg)~dataset,mean,data=cores,na.rm=T)
# standard deviation
dataset_slowP_sd <- aggregate(cbind(N_conc_percent,slow.P_conc_mg.kg)~dataset,sd,data=cores,na.rm=T)
# sample size
dataset_slowP_ss <- aggregate(cbind(N_conc_percent,slow.P_conc_mg.kg)~dataset,n(),data=cores,na.rm=T)
sum_table<-data.frame(matrix(nrow=length(unique(cores$dataset)),ncol=3))
names(sum_table) <- c('dataset', 'Slow_P.N_slope_dataset', 'Slow_P.N_.pvalue_dataset')
dataset_slowP<-subset(dataset_slowP,is.na(slow.P_conc_mg.kg)==F)
dataset_slowP<-subset(dataset_slowP,is.na(N_conc_percent)==F)
dataset_slowP<-subset(dataset_slowP,dataset!="CedarCreek_1")#remove CDR because only 1 observation
dataset_slowP<-subset(dataset_slowP,dataset!="Konza_2")#remove Konza_2 because only 1 observation
dataset_slowP<-subset(dataset_slowP,dataset!="Niwot_5")#
dataset_slowP$set<-as.numeric(as.factor(dataset_slowP$dataset))
for(i in 1:max(dataset_slowP$set)){
a<-subset(dataset_slowP,set==i)
b<-summary(lm(N_conc_percent~slow.P_conc_mg.kg,data = a))
sum_table[i,1]<-first(a$dataset)
sum_table[i,2]<-b$coefficients[2,1]
sum_table[i,3]<-b$coefficients[2,4]
}
Final_table<-merge(Final_table,sum_table,all.x = T)
# Now we'll want to add together our various types of P (conditionally)
p_sums <- sparc_v2 %>%
# First need to fill NAs with 0s to avoid making NA sums
## Pivot longer
tidyr::pivot_longer(cols = c(dplyr::starts_with("P_"),
dplyr::starts_with("Po_"),
dplyr::starts_with("ReBHsin_"),
dplyr::starts_with("Pi_")),
names_to = "names", values_to = "values") %>%
## Remove NA / missing values
dplyr::filter(!is.na(values) & nchar(values) != 0) %>%
## Pivot back to wide format and fill empty cells with 0
tidyr::pivot_wider(names_from = names, values_from = values, values_fill = 0) %>%
# Calculate slow P conditionally
## NOTE: using placeholder (obviously wrong) while we await complete methods data knowledge / inclusion in data key
dplyr::mutate(slow.P_conc_mg.kg = 1) %>%
# dplyr::mutate(slow.P_mg_kg = dplyr::case_when(
# dataset == "HJAndrews_1" ~ (P_conc_HCl_mg_kg_1M),
# dataset == "Bonanza Creek_1" ~ NA,
# dataset == "Bonanza Creek_2" ~ NA,
# dataset == "Brazil" ~ NA,
# dataset == "Calhoun" ~ (P_conc_HCl_mg_kg_1M),
# # (vvv) Data seem to only have total P but searching for Hedley fraction
# dataset == "CedarCreek_1" ~ NA,
# dataset == "Coweeta" ~ (P_conc_HCl_mg_kg_0.5M),
# # (vvv) Only have a neutral salt extraction (available P). May remove dataset entirely
# dataset == "Fernow" ~ NA,
# dataset == "FloridaCoastal" ~ (P_conc_HCl_mg_kg_1M),
# dataset == "Hubbard Brook" ~ (P_conc_HNO3_cold_mg_kg_1M),
# dataset == "Jornada_1" ~ NA,
# dataset == "Jornada_2" ~ (P_conc_HCl_mg_kg_1M),
# dataset == "Kellog_Biological_Station" ~ (Pi_conc_HCl_mg_kg_1M),
# # (vvv) Based on 2 different methodologies
# dataset == "Konza_1" ~ (P_conc_Ca_bound_mg_kg),
# dataset == "Luquillo_1" ~ NA,
# # (vvv) Re-check! assuming these are the correct units, and dilute HCl is 1M step from Hedley
# dataset == "Luquillo_2" ~ (P_conc_HCl_mg_kg_1M),
# dataset == "Niwot_1" ~ (P_conc_HCl_mg_kg_1M),
# dataset == "Niwot_2" ~ (P_conc_HCl_mg_kg), ###Checking mmolarity but likely 1M
# dataset == "Niwot_3" ~ NA,
# dataset == "Niwot_4" ~ NA,
# dataset == "Sevilleta_1" ~ (P_conc_HCl_mg_kg_1M),
# dataset == "Sevilleta_2" ~ NA,
# # (vvv) If resulting number is negative it gets set to zero
# dataset == "Toolik_1" ~ ifelse((P_conc_HCl_mg_kg_1M - P_conc_citrate_mg_kg_0.01M) < 0,
# yes = 0,
# no = P_conc_HCl_mg_kg_1M - P_conc_citrate_mg_kg_0.01M),
# TRUE ~ NA )) %>%
#TOTAL P CALCULATION
dplyr::mutate(slow.P_conc_mg.kg = 1) %>%
# dplyr::mutate(slow.P_mg_kg = dplyr::case_when(
# dataset == "HJAndrews_1" ~ (P_conc_total_mg_kg),
# dataset == "Bonanza Creek_1" ~ (P_conc_total_mg_kg),
# dataset == "Bonanza Creek_2" ~ (P_conc_total_mg_kg),
# dataset == "Brazil" ~ (P_conc_total_mg_kg),
# dataset == "Calhoun" ~ (P_conc_total_mg_kg),
# # (vvv) Data seem to only have total P but searching for Hedley fraction
# dataset == "CedarCreek_1" ~ NA,
# dataset == "Coweeta" ~ (P_conc_NH4Cl_mg_kg_1M + P_conc_HCO3_mg_kg_0.1M + P_conc_NaOH_mg_kg_0.1M + P_conc_HCl_mg_kg_0.5M + P_conc_residual),
# # (vvv) Only have a neutral salt extraction (available P). May remove dataset entirely
# dataset == "Fernow" ~ NA,
# dataset == "FloridaCoastal" ~ (P_stock_resin_mg_cm3 + P_stock_HCO3_mg_cm3_0.5M + P_stock_NaOH_mg_cm3_0.1M + P_stock_HCl_mg_cm3_1M + P_stock_residual_mg_cm3),
# dataset == "Hubbard Brook" ~ (P_conc_HNO3__mg_kg_1M),
# dataset == "Jornada_1" ~ (P_conc_total_mg_kg),
# dataset == "Jornada_2" ~ (P_conc_MgCl2_mg_kg + P_conc_NaOH_mg_kg_0.1M + P_conc_HCl_mg_kg_1M + P_conc_residual),
# dataset == "Kellog_Biological_Station" ~ (Pi_conc_resin_mg_kg + Pi_conc_NaHCO3_mg_kg_0.5M + Po_conc_NaHCO3_mg_kg_0.5M + Pi_conc_microbial_mg_kg + Po_conc_microbial_mg_kg + Pi_conc_NaOH_mg_kg_0.1M + Po_conc_NaOH_mg_kg_0.1M + Pi_conc_sonic_NaOH_mg_kg_0.1M + Po_conc_sonic_NaOH_mg_kg_0.1M + Pi_conc_HCl_mg_kg_1M + Po_conc_residual_mg_kg),
# # (vvv) Based on 2 different methodologies
# dataset == "Konza_1" ~ (P_conc_Al_Fe_mg_kg + P_conc_occluded_mg_kg + P_conc_Ca_bound_mg_kg),
# dataset == "Luquillo_1" ~ NA,
# # (vvv) Re-check! assuming these are the correct units, and dilute HCl is 1M step from Hedley
# dataset == "Luquillo_2" ~ (P_conc_total_mg_kg),
# dataset == "Niwot_1" ~ (P_conc_resin_mg_kg + Po_conc_HCO3_mg_kg_0.5M + Pi_conc_HCO3_mg_kg_0.5M+ Po_conc_NaOH_mg_kg_0.1M + Pi_conc_NaOH_mg_kg_0.1M + P_conc_HCl_mg_kg_1M + Po_conc_sonic_HCl_mg_kg_1M + Pi_conc_sonic_HCl_mg_kg_1M + P_conc_residual_mg_kg),
# dataset == "Niwot_2" ~ (P_conc_resin_mg_kg + Po_conc_HCO3_mg_kg + Pi_conc_HCO3_mg_kg + Po_conc_NaOH_mg_kg + Pi_conc_NaOH_mg_kg + P_conc_HCl_mg_kg + P_conc_residual_mg_kg),
# dataset == "Niwot_3" ~ (P_conc_total_mg_kg),
# dataset == "Niwot_4" ~ (P_conc_total_mg_kg),
# dataset == "Sevilleta_1" ~ (P_conc_total_mg_kg),
# dataset == "Sevilleta_2" ~ (P_conc_total_mg_kg),
# # (vvv) If resulting number is negative it gets set to zero
# dataset == "Toolik_1" ~ NA,
# TRUE ~ NA )) %>%
## ------------------------------------------ ##
# Within site Slow P versus Total N Figures -----
## ------------------------------------------ ##
#### Sevilleta #####
aa<-subset(cores,dataset=="Sevilleta_1")
plot<-aggregate(cbind(N_conc_percent,total.P_conc_mg.kg,slow.P_conc_mg.kg)~plot,mean, data=aa,na.rm=T)
Sevilleta_1 <-ggplot(data = aa, aes(slow.P_conc_mg.kg,N_conc_percent, fill = plot) ) +
geom_smooth(aes(group = 1), method = "lm", colour="black", se = TRUE, size=0.5, alpha=0.3) +
geom_smooth(data = plot, aes(slow.P_conc_mg.kg,N_conc_percent),method = "lm", colour="blue", se = TRUE, fill = "blue", alpha=0.15) +
geom_point(shape = 21, size = 3, color = "black", stroke = .5 ) +
geom_point(data = plot, aes(slow.P_conc_mg.kg,N_conc_percent, fill = plot),shape = 21, size=7, color = "black", stroke = .5, alpha = 0.7 ) +
ggtitle("Sevilleta") + ylab ("Soil N (%)") +
xlab(bquote(Slow~P~(mg~kg^-1))) +
theme_bw() +
theme(legend.position = "none",
panel.grid.major = element_blank(),
panel.grid.minor = element_blank() )
Sevilleta_1
summary(lm(aa$N_conc_percent ~ aa$slow.P_conc_mg.kg))
summary(lm(plot$N_conc_percent ~ plot$slow.P_conc_mg.kg))
ggsave(plot=Sevilleta_1, filename="figures/slowP_site/Sevilleta_1.png", width = 3, height = 3)
rm(aa,plot,site)
#### CALHOUN #####
aa<-subset(cores,dataset=="Calhoun")
site<-aggregate(cbind(N_conc_percent,total.P_conc_mg.kg,slow.P_conc_mg.kg)~site,mean, data=aa,na.rm=T)
Calhoun <-ggplot(data = aa, aes(slow.P_conc_mg.kg,N_conc_percent, fill = site) ) +
geom_smooth(aes(group = 1), method = "lm", colour="black", se = TRUE, size=0.5, alpha=0.3) +
# geom_smooth(data = site, aes(slow.P_conc_mg.kg,N_conc_percent),method = "lm", colour="blue", se = TRUE, fill = "blue", alpha=0.15) +
geom_point(shape = 21, size = 3, color = "black", stroke = .5 ) +
geom_point(data = site, aes(slow.P_conc_mg.kg,N_conc_percent, fill = site),shape = 21, size=7, color = "black", stroke = .5, alpha = 0.7 ) +
ggtitle("Calhoun") + ylab ("Soil N (%)") +
xlab(bquote(Slow~P~(mg~kg^-1))) +
theme_bw() +
theme(legend.position = "none",
panel.grid.major = element_blank(),
panel.grid.minor = element_blank() )
Calhoun
summary(lm(aa$N_conc_percent ~ aa$slow.P_conc_mg.kg))
summary(lm(site$N_conc_percent ~ site$slow.P_conc_mg.kg))
ggsave(plot=Calhoun, filename="figures/slowP_site/Calhoun.png", width = 3, height = 3)
rm(aa,plot,site)
#### COWEETA #####
aa<-subset(cores,dataset=="Coweeta")
site<-aggregate(cbind(N_conc_percent,total.P_conc_mg.kg,slow.P_conc_mg.kg)~site,mean, data=aa,na.rm=T)
Coweeta <- ggplot(data = aa, aes(slow.P_conc_mg.kg,N_conc_percent, fill = site) ) +
geom_smooth(aes(group = 1), method = "lm", colour="black", se = TRUE, size=0.5, alpha=0.3) +
geom_smooth(data = site, aes(slow.P_conc_mg.kg,N_conc_percent),method = "lm", colour="blue", se = TRUE, fill = "blue", alpha=0.15) +
geom_point(shape = 21, size = 3, color = "black", stroke = .5 ) +
geom_point(data = site, aes(slow.P_conc_mg.kg,N_conc_percent, fill = site),shape = 21, size=7, color = "black", stroke = .5, alpha=0.7 ) +
ggtitle("Coweeta") + ylab ("Soil N (%)") +
xlab(bquote(Slow~P~(mg~kg^-1))) +
theme_bw() +
theme(legend.position = "none",
panel.grid.major = element_blank(),
panel.grid.minor = element_blank() )
Coweeta
summary(lm(aa$N_conc_percent ~ aa$slow.P_conc_mg.kg))
summary(lm(site$N_conc_percent ~ site$slow.P_conc_mg.kg))
ggsave(plot=Coweeta, filename="figures/slowP_site/Coweeta.png", width = 3, height = 3)
rm(aa,plot,site)
#### FLO RIDA #####
# aa<-subset(cores,dataset=="FloridaCoastal")
# site<-aggregate(cbind(N_conc_percent,total.P_conc_mg.kg,slow.P_conc_mg.kg)~site,mean, data=aa,na.rm=T)
#
# f<-ggplot(aa, aes(slow.P_conc_mg.kg,N_conc_percent, colour = site)) +
# geom_point(size = 2 ) +
# geom_smooth(aes(group = 1),method = "lm", colour="black", se = FALSE) +
# geom_point(data = site, aes(slow.P_conc_mg.kg,N_conc_percent, colour = site),size=4, alpha=0.5)+
# geom_smooth(data = site, aes(slow.P_conc_mg.kg,N_conc_percent),method = "lm", colour="red", se = FALSE)+
# ggtitle("Everglades")+ xlab("Slowly Cycling P (mg/kg)") + ylab ("Soil N (%)")+
# theme_bw()
# f
#### HubbardBrook #####
aa<-subset(cores,dataset=="Hubbard Brook")
site<-aggregate(cbind(N_conc_percent,total.P_conc_mg.kg,slow.P_conc_mg.kg)~site,mean, data=aa,na.rm=T)
Hubbard_Brook <- ggplot(data = aa, aes(slow.P_conc_mg.kg,N_conc_percent, fill = site) ) +
geom_smooth(aes(group = 1), method = "lm", colour="black", se = TRUE, size=0.5, alpha=0.3) +
geom_smooth(data = site, aes(slow.P_conc_mg.kg,N_conc_percent),method = "lm", colour="blue", se = TRUE, fill = "blue", alpha=0.15) +
geom_point(shape = 21, size = 3, color = "black", stroke = .5 ) +
geom_point(data = site, aes(slow.P_conc_mg.kg,N_conc_percent, fill = site),shape = 21, size=7, color = "black", stroke = .5, alpha=0.7 ) +
ggtitle("Hubbard Brook") + ylab ("Soil N (%)") +
xlab(bquote(Slow~P~(mg~kg^-1))) +
theme_bw() +
theme(legend.position = "none",
panel.grid.major = element_blank(),
panel.grid.minor = element_blank() )
Hubbard_Brook
summary(lm(aa$N_conc_percent ~ aa$slow.P_conc_mg.kg))
summary(lm(site$N_conc_percent ~ site$slow.P_conc_mg.kg))
ggsave(plot=Hubbard_Brook, filename="figures/slowP_site/Hubbard_Brook.png", width = 3, height = 3)
rm(aa,plot,site)
#### Jornada #####
aa<-subset(cores,dataset=="Jornada_2")
site<-aggregate(cbind(N_conc_percent,total.P_conc_mg.kg,slow.P_conc_mg.kg)~site,mean, data=aa,na.rm=T)
Jornada_2<-ggplot(data = aa, aes(slow.P_conc_mg.kg,N_conc_percent, fill = site) ) +
geom_smooth(aes(group = 1), method = "lm", colour="black", se = TRUE, size=0.5, alpha=0.3, linetype="dashed") +
# geom_smooth(data = site, aes(slow.P_conc_mg.kg,N_conc_percent),method = "lm", colour="blue", se = TRUE, fill = "blue", alpha=0.15) +
geom_point(shape = 21, size = 3, color = "black", stroke = .5 ) +
geom_point(data = site, aes(slow.P_conc_mg.kg,N_conc_percent, fill = site),shape = 21, size=7, color = "black", stroke = .5, alpha=0.7 ) +
ggtitle("Jornada") + ylab ("Soil N (%)") +
xlab(bquote(Slow~P~(mg~kg^-1))) +
theme_bw() +
theme(legend.position = "none",
panel.grid.major = element_blank(),
panel.grid.minor = element_blank() )
Jornada_2
summary(lm(aa$N_conc_percent ~ aa$slow.P_conc_mg.kg))
summary(lm(site$N_conc_percent ~ site$slow.P_conc_mg.kg))
ggsave(plot=Jornada_2, filename="figures/slowP_site/Jornada_2.png", width = 3, height = 3)
rm(aa,plot,site)
#### Luquillo #####
aa<-subset(cores,dataset=="Luquillo_2")
site<-aggregate(cbind(N_conc_percent,total.P_conc_mg.kg,slow.P_conc_mg.kg)~site,mean, data=aa,na.rm=T)
Luquillo_2<-ggplot(data = aa, aes(slow.P_conc_mg.kg,N_conc_percent, fill = site) ) +
geom_smooth(aes(group = 1), method = "lm", colour="black", se = TRUE, size=0.5, alpha=0.3) +
geom_smooth(data = site, aes(slow.P_conc_mg.kg,N_conc_percent),method = "lm", colour="blue", se = TRUE, fill = "blue", alpha=0.15, linetype="dashed") +
geom_point(shape = 21, size = 3, color = "black", stroke = .5 ) +
geom_point(data = site, aes(slow.P_conc_mg.kg,N_conc_percent, fill = site),shape = 21, size=7, color = "black", stroke = .5, alpha=0.7 ) +
ggtitle("Luquillo") + ylab ("Soil N (%)") +
xlab(bquote(Slow~P~(mg~kg^-1))) +
theme_bw() +
theme(legend.position = "none",
panel.grid.major = element_blank(),
panel.grid.minor = element_blank() )
Luquillo_2
summary(lm(aa$N_conc_percent ~ aa$slow.P_conc_mg.kg))
summary(lm(site$N_conc_percent ~ site$slow.P_conc_mg.kg))
ggsave(plot=Luquillo_2, filename="figures/slowP_site/Luquillo_2.png", width = 3, height = 3)
rm(aa,plot,site)
#### Niwot #####
aa<-subset(cores,dataset=="Niwot_5")
site<-aggregate(cbind(N_conc_percent,total.P_conc_mg.kg,slow.P_conc_mg.kg)~site,mean, data=aa,na.rm=T)
Niwot_5<-ggplot(data = aa, aes(slow.P_conc_mg.kg,N_conc_percent, fill = site) ) +
geom_smooth(aes(group = 1), method = "lm", colour="black", se = TRUE, size=0.5, alpha=0.3) +
geom_smooth(data = site, aes(slow.P_conc_mg.kg,N_conc_percent),method = "lm", colour="blue", se = TRUE, fill = "blue", alpha=0.15) +
geom_point(shape = 21, size = 3, color = "black", stroke = .5 ) +
geom_point(data = site, aes(slow.P_conc_mg.kg,N_conc_percent, fill = site),shape = 21, size=7, color = "black", stroke = .5, alpha=0.7 ) +
ggtitle("Niwot Ridge") + ylab ("Soil N (%)") +
xlab(bquote(Slow~P~(mg~kg^-1))) +
theme_bw() +
theme(legend.position = "none",
panel.grid.major = element_blank(),
panel.grid.minor = element_blank() )
Niwot_5
summary(lm(aa$N_conc_percent ~ aa$slow.P_conc_mg.kg))
ggsave(plot=Niwot_5 , filename="figures/slowP_site/Niwot_5.png", width = 3, height = 3)
rm(aa,plot,site)
#### Tapajos #####
aa<-subset(cores,dataset=="Tapajos")
site<-aggregate(cbind(N_conc_percent,total.P_conc_mg.kg,slow.P_conc_mg.kg)~site,mean, data=aa,na.rm=T)
Tapajos<-ggplot(data = aa, aes(slow.P_conc_mg.kg,N_conc_percent, fill = site) ) +
# geom_smooth(aes(group = 1), method = "lm", colour="black", se = TRUE, size=0.5, alpha=0.3) +
# geom_smooth(data = site, aes(slow.P_conc_mg.kg,N_conc_percent),method = "lm", colour="blue", se = TRUE, fill = "blue", alpha=0.15) +
geom_point(shape = 21, size = 3, color = "black", stroke = .5 ) +
geom_point(data = site, aes(slow.P_conc_mg.kg,N_conc_percent, fill = site),shape = 21, size=7, color = "black", stroke = .5, alpha=0.7 ) +
ggtitle("Tapajos") + ylab ("Soil N (%)") +
xlab(bquote(Slow~P~(mg~kg^-1))) +
theme_bw() +
theme(legend.position = "none",
panel.grid.major = element_blank(),
panel.grid.minor = element_blank() )
Tapajos
summary(lm(aa$N_conc_percent ~ aa$slow.P_conc_mg.kg))
ggsave(plot=Tapajos, filename="figures/slowP_site/Tapajos.png", width = 3, height = 3)
rm(aa,plot,site)
## ------------------------------------------ ##
# COMBINED Within site Slow P versus Total N figures -----
## ------------------------------------------ ##
WithinSiteSlow <- cowplot::plot_grid(Jornada_2,Sevilleta_1,Calhoun,Coweeta,Hubbard_Brook,Luquillo_2,Niwot_5,Tapajos)
WithinSiteSlow
ggsave(plot=WithinSiteSlow, filename="figures/slowP_site/WithinSiteSlow.png", width = 13, height = 13)
## ------------------------------------------ ##
# Within site Total P versus Total N Figures -----
## ------------------------------------------ ##
# Doesn't make since for Arikaree, Hays, Smokey Valley, ChichaquaBottoms, or Konza 2 because they all have one point each
# linewidths
# solid is < 0.05
# dashed between 0.05 and .10
# no line p > .10