-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.R
2563 lines (2419 loc) · 92.3 KB
/
script.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
#### Potential source areas for atmospheric lead reaching Ny-Ålesund from
#### 2010 to 2018
#### Andrea Bazzano, Stefano Bertinetti, Francisco Ardini, David Cappelletti and
#### Marco Grotti
#### corresponding author: [email protected]
#### Supplementary material: script to reproduce the data analysis described in
#### the manuscript for chemical and isotopic data.
############################### Preamble ######################################
#### Loading of specialised libraries ----
# data manipulation
library(data.table)
library(dplyr)
library(lubridate)
# statistics
library(summarytools)
library(fitdistrplus)
library(dunn.test)
library(mclust)
library(QuantPsyc)
library(energy)
library(MASS)
# graphics
library(ggplot2)
library(ggpubr)
library(ggrepel)
library(ggforce)
library(patchwork)
library(scales)
# color-blind-friendly palette
cbPalette <- c("#999999", "#E69F00", "#56B4E9", "#009E73",
"#F0E442", "#0072B2", "#D55E00", "#CC79A7")
cbPalette1 <- c("#999999", "#E69F00", "#56B4E9", "#009E73",
"#F0E442", "#0072B2", "#CC79A7", "#D55E00")
#### Additional functions ----
# opposite of %in%
`%!in%` = Negate(`%in%`)
# Deming regression: noise_ratio is the ratio of errors on y and x
# https://en.wikipedia.org/wiki/Deming_regression
# https://stackoverflow.com/questions/26995923/
# ggplot2-how-to-plot-an-orthogonal-regression-line
deming.fit <- function(x, y, noise_ratio = sd(y)/sd(x)) {
if(missing(noise_ratio) ||
is.null(noise_ratio)) noise_ratio <-
eval(formals(sys.function(0))$noise_ratio)
# this is just a complicated way to write `sd(y)/sd(x)`
delta <- noise_ratio^2
x_name <- deparse(substitute(x))
s_yy <- var(y)
s_xx <- var(x)
s_xy <- cov(x, y)
beta1 <- (s_yy - delta*s_xx +
sqrt((s_yy - delta*s_xx)^2 + 4*delta*s_xy^2)) / (2*s_xy)
beta0 <- mean(y) - beta1 * mean(x)
res <- c(beta0 = beta0, beta1 = beta1)
names(res) <- c("(Intercept)", x_name)
class(res) <- "Deming"
res
}
deming <- function(formula, data, R = 100, noise_ratio = NULL, ...){
ret <- boot::boot(
data = model.frame(formula, data),
statistic = function(data, ind) {
data <- data[ind, ]
args <- rlang::parse_exprs(colnames(data))
names(args) <- c("y", "x")
rlang::eval_tidy(rlang::expr(deming.fit(!!!args,
noise_ratio = noise_ratio)),
data, env = rlang::current_env())
},
R=R
)
class(ret) <- c("Deming", class(ret))
ret
}
predictdf.Deming <- function(model, xseq, se, level) {
pred <- as.vector(tcrossprod(model$t0, cbind(1, xseq)))
if(se) {
preds <- tcrossprod(model$t, cbind(1, xseq))
data.frame(
x = xseq,
y = pred,
ymin = apply(preds, 2, function(x) quantile(x, probs = (1-level)/2)),
ymax = apply(preds, 2, function(x) quantile(x, probs = 1-((1-level)/2)))
)
} else {
return(data.frame(x = xseq, y = pred))
}
}
# percentage of end-member a and b in Pb isotope ratio values in x
# x, a and b must have two columns named pb208206 and pb207206.
# b has higher isotope ratio values than a.
# x has isotope ratio values between a and b.
bperc <- function(x, a, b){
ax1 <- x$pb208206 - a$pb208206
ax2 <- x$pb207206 - a$pb207206
ab1 <- b$pb208206 - a$pb208206
ab2 <- b$pb207206 - a$pb207206
100 * (1 - sqrt((ax1^2 + ax2^2) / (ab1^2 + ab2^2)))
}
# statistics for the median
median_stats <- function(x) {
median_x = median(x, na.rm = TRUE)
iqr_x = IQR(x, na.rm = TRUE)
mad_x = mad(x, na.rm = TRUE)
q1 = quantile(x, probs = 0.25, na.rm = TRUE)
q2 = quantile(x, probs = 0.75, na.rm = TRUE)
list(
median_x = median_x,
iqr_x = iqr_x,
mad_x = mad_x,
q1 = q1,
q2 = q2)}
############################### Datasets ######################################
#### PM10 samples collected at Ny-Ålesund from 2010 to 2018 ----
# date reports the sampling data in YYYY-MM-DD format.
# volume is the sampling volume in m3.
# pb_sign is = for Pb concentrarion data above limit of quantification (LoQ)
# and < for data below LoQ.
# pb_val is numeric and it is the measured Pb concentration or LoQ in pg/m3.
# pb is text and it is the measured Pb concentration or <LoQ in pg/m3.
# al_ef is the enrichment factor (EF) EF(Pb/Al)c in comparison to the upper
# continental crust (UCC, Wedepohl 1995).
# pb20x20y is the value measured for 20xPb / 20yPb isotope ratio.
# u20x20y is the 95-confidence level uncertainty for the measured 20xPb / 20yPb
# isotope ratio value.
# Missing values are reported as NA
nya_pm <- fread(input = "dataset/nyalesund_2010-2018.csv", skip = 15)[,
date := as.POSIXct(date)][, # convert to date
`:=` (year_col = year(date), # extract the year
month_col = month(date, # extract the month
label = TRUE,
locale = "en_GB.UTF8"))][
!is.na(pb208206) & !is.na(pb207206), # number of sample
`:=` (n208206 = .N,
n207206 = .N),
by = .(year_col, month_col)][,
season := dplyr::case_when( # group by season
month_col %in% c("Feb", "Mar", "Apr", "May") ~ "spring",
month_col %in% c("Jun", "Jul", "Aug", "Sep", "Oct") ~ "summer")]
#### Pb isotope ratios for soils and sediments near Ny-Ålesund ----
# pb20x20y columns should be read as 20xPb / 20yPb.
# see reference column for author, year citations.
# Missing values are reported as NA.
mineral <- fread("dataset/soils_sediments.csv", skip = 5)
#### Pb isotope ratios for Atmospheric particulate in some relevant areas ----
# pb20x20y columns should be read as 20xPb / 20yPb.
# see reference column for author, year citations.
# Missing values are reported as NA.
atm_nh <- fread("dataset/atm_nh.csv", skip = 8)
atm_nh[, zone := ifelse(area == "russia" | area == "europe",
"eurasia",
area)]
#### Pb isotope ratios for Chinese coals ----
# pb20x20y columns should be read as 20xPb / 20yPb.
# data from Bi et al, (2017).
# Missing values are reported as NA.
chinese_coals <- fread("dataset/chinese_coals.csv", skip = 3)
#### Pb isotope ratios for possible end-members ----
# Some values resulted from the following elaborations.
# pb20x20y columns should be read as 20xPb / 20yPb.
# see reference column for author, year citations.
# Missing values are reported as NA.
endmembers <- fread("dataset/endmembers.csv", skip = 8)
#### Table S2 ----
# percentage of monthly BTs calculated by Hysplit from 2010 to 2018
# and associated to the different geographical macro-sector.
table_s2 <- fread("dataset/back_trajectories.csv", skip = 6)
table_s2[, month := factor(month, levels = tolower(month.name))]
############################# Section 3.1 #####################################
# Only the data mentioned in this section of the manuscript are reported.
# Data for tables and figures are reported in a separate section at the end
# of this file.
#### Pb concentration (pg/m3) ----
# mean and median
nya_pm[, .(
mean(pb_val, na.rm = TRUE),
median(pb_val, na.rm = TRUE))]
# median of values above the third-quartile
nya_pm[pb_val > quantile(pb_val, 0.75, na.rm = TRUE), .(
median(pb_val, na.rm = TRUE))]
# estimate density function to describe the data distribution
qqnorm(nya_pm$pb_val) # not normal
qqnorm(log(nya_pm$pb_val)) # lognormal
pb_ft <- fitdist(nya_pm$pb_val, distr = "lnorm") # parameters in log scale
# goodness of fit test with Kolmogorov-Smirnov test
ks.test(nya_pm$pb_val, "plnorm",
meanlog = pb_ft$estimate[1],
sdlog = pb_ft$estimate[2]) # p-value = 0.51.
#### Enrichment factors (EF) EF(Pb/Al)c ----
# mean
nya_pm[, .(
mean(al_ef, na.rm = TRUE))]
# estimate density function to describe the data distribution
qqnorm(nya_pm$al_ef) # not normal
qqnorm(log(nya_pm$al_ef)) # lognormal
ef_ft <- fitdist(nya_pm[!is.na(al_ef), al_ef], distr = "lnorm") # in log scale
# goodness of fit test with Kolmogorov-Smirnov test
ks.test(nya_pm$al_ef, "plnorm",
meanlog = ef_ft$estimate[1],
sdlog = ef_ft$estimate[2]) # p-value = 0.95.
#### 208Pb/206Pb and 207Pb/206Pb isotope ratio values ----
# correlation
cor.test(nya_pm$pb208206, nya_pm$pb207206, use = "complete.obs")
# Mardia's test for multivariate normality
mult.norm(nya_pm[!is.na(pb208206), .(pb208206, pb207206)]) # p-value < 0.001
# E-test for multivariate normality
mvnorm.etest(nya_pm[!is.na(pb208206),
.(pb208206, pb207206)],
R = 1000) # p-value < 0.0001
#### Seasonality ----
# Mann-Whitney test on medians
nya_pm[, lapply(.SD, function(x) wilcox.test(x ~ season)),
.SDcols = c("pb_val", "al_ef", "pb208206", "pb207206")]
# p-value < 0.001 for all investigated variables
############################# Section 3.2 #####################################
# Only the data mentioned in this section of the manuscript are reported.
# Data for tables and figures are reported in a separate section at the end
# of this file.
#### 208Pb/206Pb and 207Pb/206Pb vs 1/EF correlation ----
# correlation
cor.test(nya_pm$pb208206, 1/nya_pm$al_ef) # p-value < 0.001
cor.test(nya_pm$pb207206, 1/nya_pm$al_ef) # p-value < 0.001
# divide data into EF classes
nya_pm[, al_ef_bin := dplyr::case_when(
al_ef < 10 ~ "<10",
al_ef >= 10 & al_ef < 25 ~ "[10, 25)",
al_ef >= 25 & al_ef < 50 ~ "[25, 50)",
al_ef >= 50 & al_ef < 100 ~ "[50, 100)",
al_ef >= 100 & al_ef < 1000 ~ "≥100")][,
al_ef_bin := factor(al_ef_bin,
levels = c(
"<10",
"[10, 25)",
"[25, 50)",
"[50, 100)",
"≥100"),
labels = c(
expression(EF(Pb/Al)[c]*" < 10"),
expression("10 ≤ "*EF(Pb/Al)[c]*" < 25"),
expression("25 ≤ "*EF(Pb/Al)[c]*" < 50"),
expression("50 ≤ "*EF(Pb/Al)[c]*" < 100"),
expression(EF(Pb/Al)[c]*" ≥ 100")),
ordered = TRUE)]
# linear models
nya_pm[, lapply(.SD, median, na.rm = TRUE), # median by EF classes
.SDcols = c("pb208206", "pb207206", "al_ef"),
by = al_ef_bin] %>%
lm(data =., cbind(pb208206, pb207206) ~ I(1/al_ef)) %>%
summary
nya_pm[, lapply(.SD, median, na.rm = TRUE), # median by EF classes
.SDcols = c("pb208206", "pb207206", "al_ef"),
by = al_ef_bin] %>%
rlm(data =., pb208206 ~ I(1/al_ef)) %>%
summary
nya_pm[, lapply(.SD, median, na.rm = TRUE), # median by EF classes
.SDcols = c("pb208206", "pb207206", "al_ef"),
by = al_ef_bin] %>%
rlm(data =., pb207206 ~ I(1/al_ef)) %>%
summary
# same result by ordinary least-squares and iterated re-weighted least squares
#### Predict possible end-members for EF = 1 and EF ~ Inf ----
nya_pm[, lapply(.SD, median, na.rm = TRUE), # median by EF classes
.SDcols = c("pb208206", "pb207206", "al_ef"),
by = al_ef_bin] %>%
lm(data =., cbind(pb208206) ~ I(1/al_ef)) %>%
predict(newdata = data.frame(al_ef = c(1, 10^6)),
interval = "confidence")
# EF = 1: 208Pb/206Pb = 2.041 +- 0.011
# EF ~ Inf: 208Pb/206Pb = 2.100 +- 0.003
nya_pm[, lapply(.SD, median, na.rm = TRUE), # median by EF classes
.SDcols = c("pb208206", "pb207206", "al_ef"),
by = al_ef_bin] %>%
rlm(data =., cbind(pb207206) ~ I(1/al_ef)) %>%
predict(newdata = data.frame(al_ef = c(1, 10^6)),
interval = "confidence")
# EF = 1: 207Pb/206Pb = 0.8098 +- 0.012
# EF ~ Inf: 207Pb/206Pb = 0.863 +- 0.001
# values for calculated anthropogenic end-members (EF ~ Inf) and natural
# end-member (EF = 1) in "endmembers" data.frame.
#### Estimate mean crustal contribution ----
nya_pm[, lapply(.SD, mean, na.rm = TRUE),
.SDcols = c("pb208206", "pb207206")] %>%
bperc(b = endmembers[3, ],
a = endmembers[4, ])
max_nat <- nya_pm[, lapply(.SD, mean, na.rm = TRUE),
.SDcols = c("pb208206", "pb207206")] %>%
bperc(b = endmembers[3, c(2, 3)]+ c(0.003, 0.001),
a = endmembers[4, c(2, 3)] + c(0.011 , 0.012))
min_nat <- nya_pm[, lapply(.SD, mean, na.rm = TRUE),
.SDcols = c("pb208206", "pb207206")] %>%
bperc(b = endmembers[3, c(2, 3)] - c(0.003, 0.001),
a = endmembers[4, c(2, 3)] - c(0.011 , 0.012))
# 5-16% with a mean contribution of ~10%
#### Estimate crustal contribution to Pb concentration (pg/m3) ----
nya_pm[, median(pb_val, na.rm = TRUE)] * c(max_nat, min_nat) / 100
# 1-4 pg/m3
############################# Section 3.3 #####################################
# Only the data mentioned in this section of the manuscript are reported.
# Data for tables and figures are reported in a separate section at the end
# of this file.
#### Percentage of significantly enriched samples ----
nya_pm[al_ef > 10, .N]/nya_pm[!is.na(al_ef), .N]*100
# 83% of data with reported EF(Pb/Al)c has EF > 10
#### Median +- IQR Pb isotope ratio values for the two seasons ----
nya_pm[, .(median = lapply(.SD, median_stats, na.rm = TRUE),
iqr = lapply(.SD, IQR, na.rm = TRUE)),
.SDcols = c("pb208206", "pb207206")]
# 208Pb/206Pb = 2.098+-0.016 and 207Pb/206Pb = 0.861+-0.009 (median +- IQR)
nya_pm[, .(median = lapply(.SD, median, na.rm = TRUE),
iqr = lapply(.SD, IQR, na.rm = TRUE)),
.SDcols = c("pb208206", "pb207206"),
by = "season"]
# ratio season median iqr
# 208Pb/206Pb spring 2.101 0.01
# 207Pb/206Pb spring 0.862 0.004
# 208Pb/206Pb summer 2.091 0.021
# 207Pb/206Pb summer 0.857 0.011
#### Gaussian Mixture Modeling (GMM) ----
# modeling
nya_gmm <- Mclust(
as.matrix(
nya_pm[!is.na(pb208206) &
!is.na(al_ef),
.(pb207206,
pb208206,
log_ef = log10(al_ef), # log EFs for normality
log_pb = log10(pb_val))] # log Pb for normality
)
)
# summary of the model
plot(nya_gmm, "BIC")
nya_gmm_summary <-summary(nya_gmm, parameters = TRUE)
# cluster 1 is cluster A: Central Asia
# cluster 2 is cluster B: North America
# bootstrap for confidence intervals of the parameters (slow)
nya_gmm_boot <- MclustBootstrap(nya_gmm, nboot = 10^3)
nya_gmm_boot_summary <- summary(nya_gmm_boot, "ci")
# cluster 1 is cluster A: Central Asia
# cluster 2 is cluster B: North America
# saving parameters in a data.frame
nya_gmm_parameters <- data.table(
parameters = c(rep("mean", 2), # mean
rep("sd", 2), # sd
rep("ci95_sup", 2), # 95conf. lvl. upper
rep("ci95_inf", 2), # 95conf. lvl. lower
rep("df_mean", 2)), # density f. at mean
cluster = c(1, 2, 1, 2, 1, 2, 1, 2, 1, 2),
rbind(
t(nya_gmm_summary$mean),
sqrt(diag(nya_gmm_summary$variance[,,1])),
sqrt(diag(nya_gmm_summary$variance[,,2])),
summary(nya_gmm_boot, "ci")$mean[,,1][2,],
summary(nya_gmm_boot, "ci")$mean[,,2][2,],
summary(nya_gmm_boot, "ci")$mean[,,1][1,],
summary(nya_gmm_boot, "ci")$mean[,,2][1,],
dnorm(nya_gmm_summary$mean[1, ],
mean = nya_gmm_summary$mean[1, ],
sd = sqrt(diag(nya_gmm_summary$variance[,,1]))),
dnorm(nya_gmm_summary$mean[2, ],
mean = nya_gmm_summary$mean[2, ],
sd = sqrt(diag(nya_gmm_summary$variance[,,2])))
)
)
# add clusters to the PM10 samples dataset
nya_pm[!is.na(pb208206) &
!is.na(al_ef),
cluster := nya_gmm_summary$classification]
#### Characterizing the clusters -----
# proportion of samples from spring and summer in the two clusters
nya_pm[!is.na(cluster), .(season, cluster)] %>%
table %>%
prop.table(margin = 2)
# test for significance of the different number of samples
nya_pm[!is.na(cluster), .(season, cluster)] %>%
table %>%
chisq.test
# p-value < 0.001
# Pb concentrations and EFs for the two clusters
nya_pm[!is.na(cluster),
.(median = lapply(.SD, median, na.rm = TRUE),
iqr = lapply(.SD, mad, na.rm = TRUE)),
.SDcols = c("pb_val", "al_ef"),
by = "cluster"]
# testing for differences
wilcox.test(data = nya_pm, pb_val ~ cluster, na.action = na.exclude)
wilcox.test(data = nya_pm, al_ef ~ cluster, na.action = na.exclude)
# p-value < 0.001
# proportion of anthropogenic Pb associated to each cluster
nya_pm[!is.na(cluster) & al_ef > 10,
.(pb = sum(pb_val, na.rm = TRUE)),
by = cluster][,
.(pb_prop = pb/sum(pb),
cluster)]
############################# Section 3.4 #####################################
# Only the data mentioned in this section of the manuscript are reported.
# Data for tables and figures are reported in a separate section at the end
# of this file.
#### Temporal variations in Pb concentration, EF and isotope ratios ----
#### Seasonality ----
wilcox.test(data = nya_pm, pb_val ~ season, na.action = na.exclude)
wilcox.test(data = nya_pm, al_ef ~ season, na.action = na.exclude)
wilcox.test(data = nya_pm, pb208206 ~ season, na.action = na.exclude)
wilcox.test(data = nya_pm, pb207206 ~ season, na.action = na.exclude)
# p-value < 0.001
# variations by month
kruskal.test(data = nya_pm, pb_val ~ month_col, na.action = na.exclude)
kruskal.test(data = nya_pm, al_ef ~ month_col, na.action = na.exclude)
kruskal.test(data = nya_pm, pb208206 ~ month_col, na.action = na.exclude)
kruskal.test(data = nya_pm, pb207206 ~ month_col, na.action = na.exclude)
# p-value < 0.001
# Post-Hoc Dunn's test for pair comparisons
with(nya_pm, dunn.test(pb_val, month_col, method = "bh"))
with(nya_pm, dunn.test(al_ef, month_col, method = "bh"))
with(nya_pm, dunn.test(pb208206, month_col, method = "bh"))
with(nya_pm, dunn.test(pb207206, month_col, method = "bh"))
# significant differences only between spring and summer months
#### Inter-annual variations ----
kruskal.test(data = nya_pm, pb_val ~ year_col, na.action = na.exclude)
p-value = 0.2
kruskal.test(data = nya_pm, al_ef ~ year_col, na.action = na.exclude)
kruskal.test(data = nya_pm, pb208206 ~ year_col, na.action = na.exclude)
kruskal.test(data = nya_pm, pb207206 ~ year_col, na.action = na.exclude)
# p-value < 0.001
# Post-Hoc Dunn's test for pair comparisons
with(nya_pm, dunn.test(al_ef, year_col, method = "bh"))
nya_pm[year_col == "2018",
.(median = median(al_ef, na.rm = TRUE),
iqr = mad(al_ef, na.rm = TRUE))]
# EF = 21 +- 18
nya_pm[year_col != "2018",
.(median = median(al_ef, na.rm = TRUE),
iqr = mad(al_ef, na.rm = TRUE))]
# EF = 38 +- 37
# Pb sampled in 2018 is less anthropogenically enriched compared to other years
with(nya_pm, dunn.test(pb208206, year_col, method = "bh"))
with(nya_pm, dunn.test(pb207206, year_col, method = "bh"))
nya_pm[, .(median = lapply(.SD, median, na.rm = TRUE),
iqr = lapply(.SD, IQR, na.rm = TRUE)),
.SDcols = c("pb208206", "pb207206"),
by = "year_col"]
# 2015 and 2018 have lower isotope ratio values compared to other years
# taking into account only summer samples
with(nya_pm[season == "summer"],
dunn.test(pb208206, year_col, method = "bh"))
with(nya_pm[season == "summer"],
dunn.test(pb207206, year_col, method = "bh"))
nya_pm[season == "summer",
.(median = lapply(.SD, median, na.rm = TRUE),
iqr = lapply(.SD, IQR, na.rm = TRUE),
n = sum(!is.na(pb208206))),
.SDcols = c("pb208206", "pb207206"),
by = "year_col"]
# differences confirmed
#### Contributions of the two clusters ----
# version 1
# nya_pm[!is.na(cluster),
# .(pb = sum(pb_val, na.rm = TRUE),
# pbm = mean(pb_val, na.rm = TRUE)),
# by = .(cluster, year_col, season)][,
# .(pb = pb / sum(pb) * pbm,
# pb_prop = pb/sum(pb),
# cluster),
# by = .(year_col, season)][
# order(year_col, season, cluster)][,
# .(median = median(pb_prop),
# q1 = quantile(pb_prop, 0.25),
# q2 = quantile(pb_prop, 0.75)),
# by = c("cluster", "season")]
# Relative contribution: version 2
nya_pm[season == "spring",.(year_col, cluster)] %>%
table %>%
prop.table(margin = 1) %>%
apply(2, median_q1q3)
nya_pm[season == "spring",. (year_col, cluster)] %>%
table %>%
pairwise.prop.test(p.adjust.method = "BH")
nya_pm[season == "summer",. (year_col, cluster)] %>%
table %>%
prop.table(margin = 1) %>%
apply(2, median_q1q3)
nya_pm[season == "summer",. (year_col, cluster)] %>%
table %>%
pairwise.prop.test(p.adjust.method = "BH")
# 2015 and 2018 have higher proportion of cluster 2 compared with 2011, 2012
# Contribution to Pb concentration (pb/m3)
nya_pm[!is.na(cluster),
lapply(.SD, median_stats),
.SDcols = c("pb_val"),
by = c("season", "cluster")]
wilcox.test(data = nya_pm[cluster == 1], pb_val ~ season)
wilcox.test(data = nya_pm[cluster == 2], pb_val ~ season)
################################ Tables #######################################
#### Table 1 ----
descr(nya_pm[, .(pb_val, al_ef, pb208206, pb207206)], round.digits = 3)
# n > LoQ for Pb
nya_pm[pb_sign == "=", .N]
#### Table 2 ----
nya_gmm_parameters[1:4, ]
nya_gmm_summary$variance
#### Table S1 ----
nya_pm[, .(id,
date,
pb_conc = ifelse(pb_sign == "<", paste0(pb_sign, pb_val), pb_val),
efs = al_ef,
pb208206,
u208206,
pb207206,
u207206)]
################################ Figures #######################################
### Setting the frame for a three isotope plot with data for atmoshperic Pb
theme.size = 20
geom.text.size = (theme.size - 4) * 0.352777778
# labels
isotext <- data.table(label = c("China",
"USA",
"Canada",
"Europe and\n Russia"),
f207206 = c(0.862, 0.825, 0.86, 0.89),
f208206 = c(2.1216, 2.025, 2.075, 2.125),
f208204 = c(38.5, 39, 38.5, 37),
f207204 = c(15.65, 15.8, 15.75, 15.5))
# common base plot
iso208207206_atm <- ggplot() +
stat_ellipse(data = atm_nh,
aes(x = pb207206,
y = pb208206,
group = zone),
geom = "polygon",
type = "norm",
fill = "white",
col = "black") +
geom_text_repel(data = isotext,
aes(x = f207206,
y = f208206,
label = label),
nudge_x = c(-0.02, +0.015, 0.03, 0.03),
nudge_y = c(0.025, -0.015, -0.025, -0.05),
size = geom.text.size) +
scale_y_continuous(breaks = seq(from = 1.7,
to = 2.3,
by = 0.02),
limits = c(1.7, 2.3)) +
scale_x_continuous(breaks = seq(from = 0.7,
to = 1.0,
by = 0.01),
limits = c(0.7, 1.0)) +
labs(x = expression({}^207*"Pb/"*{}^206*"Pb"),
y = expression({}^208*"Pb/"*{}^206*"Pb"),
col = element_blank()) +
theme_bw(base_size = theme.size)
#### Figure 1 ----
iso208207206_atm +
# 95% confidence interval ellipses for PM10 data sorted by EF classes
stat_ellipse(data = nya_pm[!is.na(al_ef_bin)],
aes(
y = pb208206,
x = pb207206,
fill = al_ef_bin,
),
geom = "polygon",
linetype = "solid",
alpha = 0.7) +
# 95% confidence interval ellipses for sediment Pb isotope ratio values
stat_ellipse(data = mineral[site %like% "sediments"],
aes(
x = pb207206,
y = pb208206),
geom = "polygon",
linetype = "solid",
alpha = 0.5) +
# confidence ellipses around mean isotope ratio for EF classes
stat_conf_ellipse(data = nya_pm[!is.na(al_ef_bin)],
aes(y = pb208206,
x = pb207206,
fill = al_ef_bin),
size = 0.5,
col = "black",
linetype = "solid",
geom = "polygon") +
# Pb isotope ratio values for PM10 a Ny-Ålesund
geom_point(data = nya_pm,
aes(
x = pb207206,
y = pb208206,
shape = "PM10"
),
size = 2,
col = "gray20") +
# Pb isotope ratio values for possibile mineral contributions
geom_point(data = mineral,
aes(
x = pb207206,
y = pb208206,
shape = site
),
size = 2,
col = "black") +
# regression line through EF medians
geom_smooth(data = nya_pm[,
lapply(.SD, median, na.rm = TRUE),
.SDcols = c("pb_val", "pb208206",
"pb207206", "al_ef"),
by = .(al_ef_bin)][!is.na(al_ef_bin)],
aes(
x = pb207206,
y = pb208206
),
col = "black",
linetype = "longdash",
method = "lm",
fullrange = TRUE) +
# medians for EF classes
geom_point(data = nya_pm[,
lapply(.SD, median, na.rm = TRUE),
.SDcols = c("pb_val", "pb208206",
"pb207206", "al_ef"),
by = .(al_ef_bin)][!is.na(al_ef_bin)],
aes(
x = pb207206,
y = pb208206,
fill = al_ef_bin
),
shape = 23,
size = 4) +
# possible end-members
geom_point(data = endmembers[1:4, ],
aes(
x = pb207206,
y = pb208206
),
size = 4,
col = "red") +
# labels for the end-members
geom_text_repel(data = endmembers[1:4, ],
aes(
x = pb207206,
y = pb208206,
label = label),
nudge_x = c(-0.005, -0.002, -0.025, -0.005),
nudge_y = c(0.03, 0.03, 0.022, -0.025),
min.segment.length = unit(0, 'lines'),
size = geom.text.size) +
# adding label on top of regression line
geom_text(data = data.table(
pb208206 = c(2.142),
pb207206 = c(0.8963),
slope = c(1.09653),
r2 = c(0.999),
label = c("through~EF~medians")
),
aes(
x = pb207206,
y = pb208206,
angle = 180 * atan(slope / 2.80) / pi,
label = paste(label, "~(R^2 ==", r2, ")")
),
size = geom.text.size-0.6444,
parse = TRUE) +
# adding explanatory ellipses and points
geom_ellipse(aes(
x0 = 0.879,
y0 = 1.99,
a = 0.01,
b = 0.01,
angle = 0),
col = NA,
fill = "gray80",
alpha = 0.5
) +
geom_ellipse(aes(
x0 = 0.879,
y0 = 1.99,
a = 0.003,
b = 0.003,
angle = 0),
col = "black",
fill = "gray80") +
geom_point(aes(
x = 0.880,
y = 1.9915
),
col = "black",
fill = "gray80",
shape = 23,
size = 3) +
# explanatory labels
geom_text_repel(data =
data.frame(pb208206 = c(1.99, 1.99, 1.9915),
pb207206 = c(0.871, 0.879, 0.880),
label = c("95%-confidence interval\n of the data",
"95%-confidence interval\n of the mean",
"median")),
aes(
x = pb207206,
y = pb208206,
label = label),
nudge_x = c(-0.025, 0, +0.01),
nudge_y = c(0, 0.025, 0.01),
min.segment.length = unit(0, 'lines'),
size = geom.text.size) +
# uncertainty on y axis
geom_errorbar(data = nya_pm[,
.(u208206_med = median(u208206, na.rm = TRUE),
u207206_med = median(u207206, na.rm = TRUE))],
aes(x = 0.905,
ymin = 1.99 - u208206_med,
ymax = 1.99 + u208206_med),
width = 0.002) +
# uncertainty on x axis
geom_errorbarh(data = nya_pm[,
.(u208206_med = median(u208206, na.rm = TRUE),
u207206_med = median(u207206, na.rm = TRUE))],
aes(y = 1.99,
xmin = 0.905 - u207206_med,
xmax = 0.905 + u207206_med),
height = 0.005) +
# specifing median uncertainty
geom_text(
aes(x = 0.905,
y = 2.008),
label = "median\n uncertainty",
size = geom.text.size) +
# selecting shapes and labels for data points
scale_shape_manual(breaks = c("PM10",
"Kongsfjorden sediments",
"Gruvebadet Laboratory",
"Zeppelin Observatory",
"road"),
labels = c(expression("PM"[10]~ "at Ny-Ålesund"),
"Kongsfjorden sediments",
"Gruvebadet Laboratory",
"Zeppelin Observatory",
"Ny-Ålesund road dust"),
values = c(3, 15, 20, 17, 4)) +
# selecting colours and labels for EF classses
scale_color_manual(name = expression("PM"[10]~"Enrichment factors"),
labels = scales::parse_format(),
values = cbPalette[-c(1,2, 6)]) +
scale_fill_manual(name = expression("PM"[10]~"Enrichment factors"),
labels = scales::parse_format(),
values = cbPalette[-c(1,2, 6)]) +
# adjusting the layout
theme(legend.text.align = 0,
legend.justification = c(0, 1),
legend.position = "bottom",
legend.direction = "vertical",
legend.box = "horizontal",
text = element_text(size = theme.size)) +
# ordering the legend guides
guides(shape = guide_legend(order = 1,
title = element_blank()),
colour = guide_legend(order = 2)) +
# dixed aspect ratio
coord_fixed(ratio = 1/2.80,
xlim = c(0.80, 0.91),
ylim = c(1.982, 2.185)) +
# saving the plot
ggsave(file = "output/figure1.pdf", device = cairo_pdf,
width = 297, height = 297, unit = "mm",
scale = 0.9) +
ggsave(file = "output/figure1.png", dpi = 300,
width = 297, height = 297, unit = "mm",
scale = 0.9)
#### Figure 2 ----
# Upper main panel: 207Pb/206Pb vs 208Pb/206Pb sorted by cluster
nya_cluster.plot <-
iso208207206_atm +
# weigheted average for chinese coals
stat_conf_ellipse(data = chinese_coals,
aes(
x = pb207206+0.0054, # adjustment for matching Bi 2017
y = pb208206+0.0133
),
geom = "polygon",
fill = "white",
col = "black") +
# PM10 data divided by cluster
geom_point(data = nya_pm,
aes(
x = pb207206,
y = pb208206,
col = factor(cluster),
group = factor(cluster)
)) +
# confidence ellipses for clusters
stat_ellipse(
data = nya_pm,
aes(
x = pb207206,
y = pb208206,
col = factor(cluster),
group = factor(cluster)
),
type = "t",
geom = "path",
size = 1) +
# adjusting color for clusters
scale_color_manual(name = element_blank(),
labels = c("cluster A: Central Asia",
"cluster B: North America"),
na.translate = FALSE,
drop = TRUE,
values = cbPalette[c(8, 4)]) +
# line by deming regression and u(208Pb/206Pb) = 2 u(207Pb/206)
geom_smooth(data = nya_pm,
aes(x = pb207206,
y = pb208206),
method = deming,
method.args = list(noise_ratio = 2),
col = "black",
linetype = "longdash",
fullrange = TRUE) +
# Pb isotope ratio values for possible end-members
geom_point(data = endmembers[c(5,6),],
aes(
x = pb207206,
y = pb208206
),
size = 4,
col = "red") +
# labels for the possible end-members
geom_text_repel(data = endmembers[c(5,6),],
aes(
x = pb207206,
y = pb208206,
label = label),
nudge_x = c(0.0, -0.02),
nudge_y = c(0.07, 0.01),
min.segment.length = unit(0, 'lines'),
size = geom.text.size) +
# label for regression line
geom_text(data =
data.table(
pb208206 = 2.11,
pb207206 = 0.875,
slope = 1.9,
r2 = 0.683,
label = "through~PM[10]~data"),
aes(
x = pb207206,
y = pb208206,
angle = 180 * atan(slope / 2.80) / pi,
label = paste(label, "~(R^2 ==", r2, ")")
),
size = geom.text.size - 0.64444,
hjust = 0,
vjust = 0,
parse = TRUE) +
# theme layout
coord_fixed(ratio = 1/2.80,
xlim = c(0.80, 0.91),
ylim = c(1.982, 2.185)) +
theme_bw() +
theme(legend.position = c(0.95, 0.05),
legend.justification = c(1, 0),
text = element_text(size = theme.size))
# upper marginal histogram and density plot
nya207206_cluster <-
ggplot() +
# histogram for 207Pb/206Pb values sorted by cluster
geom_histogram(data = nya_pm[!is.na(cluster)],
aes(
x = pb207206,
fill = factor(cluster),
group = factor(cluster),
y = ..density..),
position = "identity",
binwidth = 0.003,
alpha = 0.6,
col = "white") +
stat_function(fun = function(x) dnorm(x,
mean = nya_gmm_parameters$pb207206[1],
sd = nya_gmm_parameters$pb207206[3]),
n = 1000,
col = cbPalette[c(8)],
size = 1) +
stat_function(fun = function(x) dnorm(x,
mean = nya_gmm_parameters$pb207206[2],
sd = nya_gmm_parameters$pb207206[4]),
n = 1000,
col = cbPalette[c(4)],
size = 1) +
# segment for the mean value
geom_segment(
aes(
x = nya_gmm_parameters$pb207206[1:2],
xend = nya_gmm_parameters$pb207206[1:2],
y = 0,
yend = nya_gmm_parameters$pb207206[9:10]),
col = cbPalette[c(8, 4)],
linetype = "dashed",
size = 1) +
# add standard error of the mean
geom_pointrange(aes(
xmin = nya_gmm_parameters$pb207206[7:8],
xmax = nya_gmm_parameters$pb207206[5:6],
x = nya_gmm_parameters$pb207206[1:2],
y = 0
),
col = cbPalette[c(8, 4)],
fatten = 2,
size = 1) +
scale_fill_manual(name = element_blank(),
guide = NULL,
values = cbPalette[c(8, 4)]) +
scale_x_continuous(
name = bquote(phantom(.) ^ 207 * Pb ~ "/" * phantom(.) ^ 206 * Pb),
breaks = seq(0.80, 0.91, by = 0.01),
limits = c(0.80, 0.91)) +