-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1.SoilDataEus.R
2822 lines (2332 loc) · 117 KB
/
1.SoilDataEus.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
#############################################################################################################################################
### author: Mercedes Roman Dobarco
### email: mercedes.roman@bc3research.org
### Objective: Compile datasets of soil data for the Basque Country
### 1.Plot with leaflet
### Desired extent: Basque Country
### Resolution: Not decided yet. probably 30m
### CRS: EPSG=4326 (???)
### Author: Mercedes Roman Dobarco
### Date: 18/05/2023
####### Load packages
### Read and manage data
library(readxl)
library(xlsx)
library(dplyr)
library(tidyverse)
library(Hmisc)
### Spatial
library(sf)
library(terra)
library(gdalUtilities)
### Visualization
library(lattice)
library(ggplot2)
library(viridis) # color palettes
library(scales)
library(rasterVis)
library(gridExtra)
library(rasterVis)
library(RColorBrewer)
#remotes::install_github('r-tmap/tmap')
library(tmap) # for static and interactive maps
library(leaflet) # for interactive maps
library(mapview) # for interactive maps
library(shiny) # for web applications
# 1. INES data ------------------------------------------------------------
### Read INES data
setwd("C:/Users/mercedes.roman/Desktop/SELVANS/WP1/Soil_data/INES datuak (2018)")
ines_a <- read_excel("Araba/DatParcelasA.xlsx")
ines_b <- read_excel("Bizkaia/DatParcelas.xlsx")
ines_c <- read_excel("Gipuzkoa/DatParcelasG.xlsx")
setdiff(colnames(ines_a), colnames(ines_b))
setdiff(colnames(ines_a), colnames(ines_c))
setdiff(colnames(ines_c), colnames(ines_a))
setdiff(colnames(ines_b), colnames(ines_c))
setdiff(colnames(ines_c), colnames(ines_b))
### change colnames and create missing column in ines_b
colnames(ines_a)[colnames(ines_a) == "Probintzia"] <- "Provincia"
ines_b$Provincia <- "Bizkaia"
### ines dataset
ines <- full_join(ines_a,ines_b)
ines <- full_join(ines,ines_c)
rm(ines_a, ines_b, ines_c)
names(ines)
### Transform into spatial
ines_sf <- st_as_sf(ines, coords = c("CoordXpm","CoordYpm"), crs = 25830)
### Project
ines_WGS84 <- st_transform(ines_sf, 4326)
coords_wgs84 <- st_coordinates(ines_WGS84)
ines$Latitude <- coords_wgs84[,2]
ines$Longitude <- coords_wgs84[,1]
rm(ines_WGS84, coords_wgs84)
### INES has some field observations on soil physical and hydraulic properties,
### like erosion, permeability, soil structure
table(ines$Estructura)
# 0 1 2 3 4
# 7 119 90 65 46
table(ines$CodLitologiaCampo)
table(ines$CodPermeabilidad)
# 0 2 3 4 5 6
# 7 5 1 76 40 198
### Transform some variables
### Probably I will just keep clay, sand, silt, OM%, coarse fragments (%), bulk density (g/cm3)
### From an email from TRAGSATEC I know that
### "Las muestras de suelo del INES que se analizan en laboratorio son de los 10 cm superiores del suelo (0-10cm)."
ines$Upper_limit <- 0
ines$Lower_limit <- 10
### Change colnames or copy columns to have same name as in Carbosol
colnames(ines)[colnames(ines)== "Provincia"] <- "Province"
colnames(ines)[colnames(ines)== "CoordXpm"] <- "UTM_X"
colnames(ines)[colnames(ines)== "CoordYpm"] <- "UTM_Y"
colnames(ines)[colnames(ines)== "Altpm"] <- "Elevation"
colnames(ines)[colnames(ines)== "Arena"] <- "Sand"
colnames(ines)[colnames(ines)== "Limo"] <- "Silt"
colnames(ines)[colnames(ines)== "Arcilla"] <- "Clay"
colnames(ines)[colnames(ines)== "MO"] <- "OM"
### We don´t know for certain that the coarse fragments are gravimetric
### but since they are determined in the laboratory this is the most likely
ines$CoarseFrag_Grav <- ines$EG
### Transformation of bulk density to the correct units
ines$Bulk_Density <- ines$DA/1000
### Indicate information on Bulk Density method
ines$BD_method <- "Disturbed sample with coarse fragments"
ines$BD_quality <- "low"
### Transformation of OM to TOC % with conversion factor
ines$TOC <- ines$OM / 1.724
### I keep active carbonate because there is data from BASONET on this
ines$Act_carbonates <- ines$CalizaActiva
# ### I keep Thickness O horizon with new name
# ines$Thickness_O <- ines$ProfMO
### Indicate dataset
ines$Dataset <- "INES"
### Indicate year of sampling. The exact date of fieldwork is unknown,
### but the closest year is 2018.
ines$Date <- 2018
### Create my ID
ines$myID <- paste0(ines$Dataset,"_",ines$CodParcela)
### Subset of columns to merge
ines_sub <- ines[,c("myID","Dataset","Province","Date",
"UTM_X","UTM_Y","Longitude","Latitude",
"Upper_limit","Lower_limit",
"Sand","Silt","Clay",
"OM","TOC",
"Bulk_Density","BD_method", "BD_quality",
"CoarseFrag_Grav","Act_carbonates")]
summary(ines_sub$Bulk_Density)
# Min. 1st Qu. Median Mean 3rd Qu. Max. NA's
# 0.4500 0.8300 0.9300 0.9267 1.0300 1.2000 8
### Is bulk density of whole soil or fine earth?
### It is in between. It is calculated with particles > 2mm
### but excluding big stones and roots.
### from a DISTURBED sample, a cylinder of known volume (Kopecky cylinder)
### Is filled with dry soil (before sieving) avoiding big stones and roots.
### Weight, and calculate bulk density after subtracting the weight of the cylinder.
### Procedimiento: Se rellena hasta el borde el cilindro de Kopecky,
### de volumen conocido, con suelo seco y sin tamizar,
### evitC!ndose elementos que no forman parte de ninguna de las fracciones del suelo,
### como piedras grandes o raC-ces. Se pesa y se anota el valor.
### La densidad aparente serC! el cociente entre el peso medido y
### el volumen fijo del cilindro de Kopecky.
### I will exclude the data of bulk density from data analysis
### INES 2018
colnames(ines_sub)
sel.columns.ines <- c("Dataset","myID","UTM_X","UTM_Y","Longitude","Latitude",
"Upper_limit","Lower_limit","Date",
# "Bulk_Density","BD_method","BD_quality",
"Sand","Silt","Clay","OM","TOC", ### Minimum dataset
"CoarseFrag_Grav","Act_carbonates")
ines_m <- ines_sub[,sel.columns.ines]
# 2. CARBOSOL -------------------------------------------------------------
setwd("C:/Users/mercedes.roman/Desktop/SELVANS/WP1/Soil_data/CARBOSOL/")
carbosol_horizons <- read_csv("carbosol_horizons_mrd.csv")
carbosol_profiles <- read_csv("carbosol_profiles_mrd.csv")
### Join
carbosol <- right_join(carbosol_profiles,carbosol_horizons)
#, by=c("Id_Profile","Province", "Location", "Latitude", "Longitude", "UTM_X", "UTM_Y"))
### Transform to spatial
carbosol_sf <- st_as_sf(carbosol, coords = c("UTM_X","UTM_Y"), crs = 25830)
rm(carbosol_horizons,carbosol_profiles)
### bulk density?
summary(carbosol$Bulk_Density)
# Min. 1st Qu. Median Mean 3rd Qu. Max. NA's
# 0.620 1.200 1.370 1.353 1.500 2.650 14208
### These values agree more with bulk density of whole soil
summary(carbosol$EC)
### Sampling date?
summary(carbosol$Date)
### Load administrative boundaries of Euskadi
### the CAPV ("U:/Covariates/Administrative/CB_CAPV_5000_ETRS89/U11.CB_CAPV_5000_ETRS89.shp")
euskadi <- st_read("U:/Covariates/Administrative/CB_CAPV_5000_ETRS89/U11.CB_CAPV_5000_ETRS89.shp")
### and the rest of Spain
HomeDir <- "U:/Covariates/" ### Change this with your Home directory
setwd(paste0(HomeDir,"Administrative/SHP_ETRS89/recintos_autonomicas_inspire_peninbal_etrs89/"))
autonomias <- st_read("recintos_autonomicas_inspire_peninbal_etrs89.shp")
autonomias25830 <- st_transform(autonomias, 25830)
st_bbox(autonomias25830)
### Countries
world <- st_read("U:/Covariates/Europe/ref-countries-2020-01m.shp/CNTR_RG_01M_2020_4326.shp/CNTR_RG_01M_2020_4326.shp")
world25830 <- st_transform(world, 25830)
### subset neighbours around Euskadi
buff_Eus <- st_buffer(euskadi, dist=1000000)
plot(buff_Eus["CCAA"])
world_eus_int <- st_intersects(world25830, buff_Eus, sparse = FALSE)
world_eus <- world25830[world_eus_int,]
plot(world_eus["CNTR_ID"])
rm(buff_Eus,world,world25830,world_eus_int)
### Grey fill
tm_shape(world_eus, bbox=st_bbox(euskadi), crs=25830) +
tm_borders() +
tm_shape(autonomias25830) +
tm_fill(col="gray95") +
tm_borders() +
tm_compass(type = "arrow", position = c("left", "top")) +
tm_scalebar(breaks = c(0,20,40), text.size = 0.8, position = c("right", "bottom")) +
tm_grid(lines=FALSE) +
tm_shape(carbosol_sf) +
tm_symbols(shape=21,
size=0.3,
legend.shape.show = TRUE,
col="indianred3",
border.col="black",
title.shape = "CARBOSOL") +
tm_shape(ines_sf) +
tm_symbols(shape=24,
size=0.2,
legend.shape.show = TRUE,
col="cornflowerblue",
border.col="black",
title.shape = "INES") +
tm_layout(legend.outside=TRUE,
legend.outside.position="right",
legend.title.size=1.5,
legend.text.size=1.1)
eus_buffer <- read_sf('C:/Covariates/Euskadi/boundaries/eus_buffer_125m.shp')
eus_buffer_WGS84 <- st_transform(eus_buffer, 4326)
tm_shape(eus_buffer, bbox=st_bbox(euskadi), crs=25830) + tm_borders()
### I don't use the buffer to subset Carbosol locations,
### but the administrative limits
carbosol_Eus <- st_intersection(carbosol_sf, euskadi)
### This leaves 907 observations (I lose 36 compared if I use a buffer to subset)
tm_shape(world_eus, bbox=st_bbox(euskadi), crs=25830) +
tm_borders() +
tm_shape(autonomias25830) +
# tm_fill(col="gray95") +
tm_borders() +
tm_compass(type = "arrow", position = c("left", "top")) +
tm_scalebar(breaks = c(0,20,40), text.size = 0.8, position = c("right", "bottom")) +
tm_grid(lines=FALSE) +
tm_shape(carbosol_Eus) +
tm_symbols(shape=21,
size=0.3,
legend.shape.show = TRUE,
col="indianred3",
border.col="black",
title.shape = "CARBOSOL") +
tm_shape(ines_sf) +
tm_symbols(shape=24,
size=0.2,
legend.shape.show = TRUE,
col="cornflowerblue",
border.col="black",
title.shape = "INES") +
tm_layout(legend.outside=TRUE,
legend.outside.position="right",
legend.title.size=1.5,
legend.text.size=1.1)
### Drop the geometry. Back to dataframe
carbosol_Eus_df <- carbosol_Eus
st_geometry(carbosol_Eus_df) <- NULL
coords_carbosol_utm <- st_coordinates(carbosol_Eus)
carbosol_Eus_df$UTM_X <- coords_carbosol_utm[,1]
carbosol_Eus_df$UTM_Y <- coords_carbosol_utm[,2]
carbosol_Eus_df <- as.data.frame(carbosol_Eus_df)
### bbox for plot larger than just Euskadi
bbox_plot_Eus <- st_buffer(euskadi, dist=20000)
tm_shape(world_eus, bbox=st_bbox(bbox_plot_Eus), crs=25830) +
tm_borders() +
tm_shape(autonomias25830) +
# tm_fill(col="gray95") +
tm_borders() +
tm_compass(type = "arrow",
position = c("left", "top")) +
tm_scalebar(breaks = c(0,20,40),
text.size = 0.6,
position = c("left", "bottom")) +
tm_grid(lines=FALSE) +
tm_shape(carbosol_Eus) +
tm_symbols(col="Date",
palette="viridis",
size=0.4,
title.shape = "CARBOSOL") +
tm_layout(inner.margins = c(0,0,0,0),
legend.outside=TRUE,
legend.outside.position="right",
legend.title.size=1.2,
legend.text.size=0.8)
### How many locations?
length(unique(carbosol_Eus_df$Id_Profile)) ### 252 locations
length(unique(carbosol_Eus_df$Id_Horiz)) ### 907 horizons
library(ggplot2)
ggplot()+
geom_histogram(aes(x=Upper_limit_m), data=carbosol_Eus_df,
binwidth = 0.05,
fill="cadetblue3", col="gray30") +
labs(x="Upper horizon depth (m)")+
theme_bw()
ggplot()+
geom_histogram(aes(x=Lower_limit_m), data=carbosol_Eus_df,
binwidth = 0.05,
fill="cadetblue3", col="gray30") +
labs(x="Lower horizon depth (m)")+
theme_bw()
ggplot()+
geom_histogram(aes(x=Date), data=carbosol_Eus_df,
fill="cadetblue3", col="gray30") +
labs(x="Date")+
theme_bw()
### Indicate dataset
carbosol_Eus_df$Dataset <- "CARBOSOL"
### Create my ID
carbosol_Eus_df$myID <- paste0(carbosol_Eus_df$Dataset,"_",carbosol_Eus_df$Id_Profile)
### Horizon limits to cm
carbosol_Eus_df$Upper_limit <- carbosol_Eus_df$Upper_limit_m * 100
carbosol_Eus_df$Lower_limit <- carbosol_Eus_df$Lower_limit_m * 100
### Colnames
colnames(carbosol_Eus_df)
### CARBOSOL metadata (from "Metadata.xlxs" https://store.pangaea.de/Publications/LlorenteM_2017/Metadata.xlsx)
# "Id_Profile" Unique identification number of profile
# "Id_ref" Unique identification number of reference
# "Date" Year soil sampling
# "Province" Province
# "Location" Municipality or local toponym
# "Latitude" Latitude in WGS84
# "Longitude" Longitude in WGS84
# "N_hor" Number of horizons in the profile
# "N_hor_o" Number of horizons in the profile with organic matter measurement
# "depth_m" Depth (m) ### Note that in the metadata it says cm but this is not correct
# "LCC" Land cover class
# "LCC_code" Land cover class code
# "CORINE_l1" CORINE Land Cover Code Level 1
# "CORINE_l23" CORINE Land Cover Code Level 2-3
# "Vegetation_ref" Vegetation details provided by original reference
# "Elevation" Altitude (meters above sea level)
# "Aspect" Orientation
# "Slope_perc" Slope (%)
# "ParentMaterial_ref" Parent material by original reference
# "PM_consistency" Parent material consistency
# "PM_silica" Parent material silica content
# "SoilClass_WRB" Soil classification into WRB system
# "SoilClass_USDA" Soil classification into USDA system
# "Id_Horiz" Unique identification number of horizon
# "Hor_descrip" Horizon description/designation in the original reference
# "Hor_Pos" Horizon position in the soil profile
# "RelPosit_profile" Horizon relative position in the soil profile (qualitative)
# "Upper_limit_m" Upper limit (m) ### Note that in the metadata it says cm but it is in m
# "Lower_limit_m" Lower limit (m) ### Note that in the metadata it says cm but it is in m
# "Mid_Depth_m" Midpoint of horizon depth
# "Thickness_m" Horizon thickness (m)
# "UTM_X" UTM X coordinates
# "UTM_Y" UTM Y coordinates
# "Dataset" Dataset
# "myID" Unique ID created for this data analysis
# "Upper_limit" Upper limit in cm
# "Lower_limit" Lower limit in cm
### Soil properties - CARBOSOL METADATA
# "Color_HLS" Munsell Code
# "Bulk_Density" Bulk density g/cm3 Wide variety of methods, including application of pedotransfer functions. Block Method is the most widely used
# "CoarseFrag" Coarse material (% VOLUMETRIC) > 2 mm; % of total volume
# "Sand" Sand (%) USDA System (2mm - 50 microm)
# "Silt" Silt (%) USDA System (50-2 microm)
# "Clay" Clay (%) USDA System (< 2 microm)
# "OM" Organic matter (%) - Conversion factor of 1.724 applied when needed
# "TOC" TOC (%) Walkley-Black Method or Dry Combustion Methods (elemental analyzer)
# "pH" pH in water, Soil:water ratio 1:1, 1:2.5 or 1:5
# "Carbonates" Carbonates (%) Bernard’s Calcimeter or Titrimetry
# "C_N" Carbon and nitrogen ratio - Direct calculation, from TOC and N data
# "TN_ppm" Nitrogen ppm - Kjeldahl Method or Dry Combustion Methods (elemental analyzer)
# "P_ppm" Phosphorus ppm - Olsen or Mehlich Methods
# "K_ppm" Potasium ppm - Extraction with ammonium acetate and quantification by ICP spectroscopy or Flame Photometry Methods
# "Ca_ppm" Calcium ppm - Extraction with ammonium acetate and quantification by ICP spectroscopy or Atomic Absorption Spectrometry Methods
# "Mg_ppm" Magnesium ppm - Extraction with ammonium acetate and quantification by ICP spectroscopy or Atomic Absorption Spectrometry Methods
# "Na_ppm" Sodium ppm - Extraction with ammonium acetate and quantification by ICP spectroscopy or Flame Photometry Methods
# "CEC" Cation-exchange capacity (cmol/Kg) - Cation Summation Method
# "EC" Electric Conductivity (dS/m at 25C) - Soil:water ratio 1:5
# "Gypsum" Gypsum content (%) - Conductometry in the water extract
### Indicate bulk density quality and method
carbosol_Eus_df$BD_method <- "Core method and PTF"
carbosol_Eus_df$BD_quality <- "medium"
### Bulk density in Euskadi
summary(carbosol_Eus_df$Bulk_Density)
### quite high the maximum value!
hist(carbosol_Eus_df$Bulk_Density, breaks=30)
### We have soil order information of 106 sites
unique(carbosol_Eus_df[!is.na(carbosol_Eus_df$SoilClass_WRB),]$myID)
### Here for CARBOSOL unless I find I need to correct something else
### CARBOSOL
sel.columns.carbosol <- c("Dataset","myID","UTM_X","UTM_Y","Longitude","Latitude",
"Upper_limit","Lower_limit","Date",
"Bulk_Density","BD_method","BD_quality",
"Sand","Silt","Clay","OM","TOC", ### Minimum dataset
"Color_HLS","Carbonates",
"pH","EC","TN_ppm","P_ppm","K_ppm","Ca_ppm","Mg_ppm","Na_ppm","C_N",
"CEC","Gypsum","CoarseFrag", "SoilClass_WRB","SoilClass_USDA",
"ParentMaterial_ref","PM_consistency","PM_silica")
carbosol_m <- carbosol_Eus_df[,sel.columns.carbosol]
# 3.1 BASONET 2021 --------------------------------------------------------
library(readxl)
Basonet_2021 <- read_excel("C:/Users/mercedes.roman/Desktop/SELVANS/WP1/Soil_data/Basonet/BasonetSuelos_mrd.xlsx",
sheet = "medicion2021-2022")
Basonet_2011 <- read_excel("C:/Users/mercedes.roman/Desktop/SELVANS/WP1/Soil_data/Basonet/BasonetSuelos_mrd.xlsx",
sheet = "medicion2011")
Basonet_2001 <- read_excel("C:/Users/mercedes.roman/Desktop/SELVANS/WP1/Soil_data/Basonet/BasonetSuelos_mrd.xlsx",
sheet = "medicion2001")
Basonet_Texture_2001 <- read_excel("C:/Users/mercedes.roman/Desktop/SELVANS/WP1/Soil_data/Basonet/BasonetSuelos_mrd.xlsx",
sheet = "texturas2001")
colnames(Basonet_2021)
# [1] "UTM_X" "UTM_Y" "th" "Plot" "Horizon_Depth_Interval"
# [6] "Unique_ID" "Lab_ID" "pH" "Bulk_Density" "Ex_Acidity_vol"
# [11] "CECef_vol" "Al_CECef" "Carbonates" "P_HCl_mg-l" "OM"
# [16] "N_perc" "C_N" "EC_µS_cm" "P_Olsen_mg-l" "Ca_mg_l"
# [21] "K_mg_l" "Mg_mg_l" "Na_mg_l"
setdiff(colnames(Basonet_2001), colnames(Basonet_2021)) ### In 2001 they had mesurements in ppm
setdiff(colnames(Basonet_2021), colnames(Basonet_2001)) ### In 2021 they measured also,
# "Ex_Acidity_vol", "CECef_vol" , "Al_CECef" , "EC_µS_cm","Na_mg_l"
### BASONET 2021 variables of interest
# "UTM_X" "UTM_Y" "Plot" "Horizon_Depth_Interval"
# "pH" pH - Water extraction (ratio 1:2.5 v/v) with a pH-meter
# "Bulk_Density" to transform from mg/l to ppm - disturbed, sieved sample. it is not soil bulk density in field conditions
# "Ex_Acidity_vol" Exchangeable acidity - meq/100 ml Extraction with 0.6N barium chloride. Titration with 0.01N NaOH. (extraction ratio of 1:10 v/v)
# "CECef_vol" Effective CEC (meq/100 ml) - Calculation. Effective CEC from exchangeable cations K+, Mg2+, Ca2+, Na+, H+ and Al3+
# "Al_CECef" Al in Effective CEC (%) - Calculation.% Al in effective CEC
# "Carbonates" % CaCO3 - Bernards calcimeter. Volume of CO2 released when adding 50% HCl. (Bernard's calcimeter)
### It is only analysed in samples with pH>7.5
# "P_HCl_mg-l" Phosphorus extracted in 3% HCl (mg/l P). Extraction in 3% HCl (extraction ratio 1:20 v/v) UV-VIS spectrophotometer
# "OM" Oxidised Organic Matter (%). Oxidation of organic matter with 1N potassium dichromate
### and concentrated sulfuric acid. Titration with Mohr's Salt 0.5N. (Walkley-Black Method)
# "N_perc" Nitrogen Kjeldahl (%). Digestion in sulfuric acid and subsequent distillation in basic medium.
### The distillate is collected in ammonia fixing solution and titrated with 0.1N HCl.
# "C_N" Ratio C to N
# "EC_µS_cm" Electric conductivity - Extraction in saturated calcium sulphate (extraction ratio 1:2.5 v/v) - Conductivity meter.
# "P_Olsen_mg-l" Olsen extractable Phosphorus. Extraction in 0.5N sodium bicarbonate (extraction ratio 1:20 v/v)-UV-VIS spectrophotometer
# "Ca_mg_l"
# "K_mg_l"
# "Mg_mg_l"
# "Na_mg_l" Extractable Calcium, Magnesium, Pottasium, and Sodium in Ammonium acetate (mg/l)
### Extraction in 1N ammonium acetate (extraction ratio 1:20 v/v) OPTICAL ICP
### Harmonise variables to same units as CARBOSOL
### Indicate dataset
Basonet_2021$Dataset <- "BASONET"
### Create my ID
Basonet_2021$myID <- paste0(Basonet_2021$Dataset,"_",Basonet_2021$th,"_",Basonet_2021$Plot)
### Horizon limits
table(Basonet_2021$Horizon_Depth_Interval)
Basonet_2021$Upper_limit <- NA
Basonet_2021$Lower_limit <- NA
Basonet_2021$Upper_limit <- ifelse(Basonet_2021$Horizon_Depth_Interval == "0-20", 0,
ifelse(Basonet_2021$Horizon_Depth_Interval == "20-40", 20, NA))
Basonet_2021$Lower_limit <- ifelse(Basonet_2021$Horizon_Depth_Interval == "0-20", 20,
ifelse(Basonet_2021$Horizon_Depth_Interval == "20-40", 40, NA))
### Date
Basonet_2021$Date <- 2021
### Exchangeable acidity from meq/100 cm3 soil to meq/100 g soil
Basonet_2021$Ex_Acidity <- NA
Basonet_2021$Ex_Acidity <- Basonet_2021$Ex_Acidity_vol / Basonet_2021$Bulk_Density
### CECef from meq/100 cm3 soil to meq/ 100 g soil (equivalent to cmol/kg)
Basonet_2021$CECef <- NA
Basonet_2021$CECef <- Basonet_2021$CECef_vol / Basonet_2021$Bulk_Density
# "Carbonates" Only analysed in samples with pH>7.5.
table(Basonet_2021$Carbonates)
Basonet_2021[Basonet_2021$pH <= 7.5,]$Carbonates
Basonet_2021[Basonet_2021$pH > 7.5,]$Carbonates
summary(Basonet_2021[is.na(Basonet_2021$Carbonates),]$pH)
Basonet_2021[Basonet_2021$Carbonates == "-", ]$pH
### Assign carbonates == 0 % for pH < 7.5
Basonet_2021[Basonet_2021$pH <= 7.5,]$Carbonates <- "0"
### when carbonates "<1" I assign 0 % (In the previous version I assigned 1%)
Basonet_2021[Basonet_2021$Carbonates == "<1",]$Carbonates <- "0"
### Transform to numeric
Basonet_2021$Carbonates <- gsub(x= Basonet_2021$Carbonates, pattern=",", replacement = "." )
Basonet_2021$Carbonates <- as.numeric(Basonet_2021$Carbonates)
# OM is in % as in Carbosol
# Conversion into TOC in %
Basonet_2021$TOC <- NA
Basonet_2021$TOC <- Basonet_2021$OM / 1.724
# N_perc"
### TN from % to ppm
Basonet_2021$TN_ppm <- NA
Basonet_2021$TN_ppm <- Basonet_2021$N_perc * 10000
# "EC_µS_cm" ### EC in Basonet in µS/cm transform to dS/m as in Carbosol
Basonet_2021$EC <-NA
Basonet_2021$EC <- Basonet_2021$EC_µS_cm / 1000
### Transform extractable cations into ppm of a dry soil weight basis dividing by bulk density
### what do I do with the ones <20? In this case I assigned NA
summary(Basonet_2021$Ca_mg_l) ### just 20 NA
Basonet_2021$Ca_ppm <- NA
Basonet_2021[!is.na(Basonet_2021$Ca_mg_l),]$Ca_ppm <-
Basonet_2021[!is.na(Basonet_2021$Ca_mg_l),]$Ca_mg_l /
Basonet_2021[!is.na(Basonet_2021$Ca_mg_l),]$Bulk_Density
table(Basonet_2021$Mg_mg_l) ### 129 values <20. But there are some readings with 10...
Basonet_2021$Mg_ppm <- NA
Basonet_2021[Basonet_2021$Mg_mg_l == "< 20",]$Mg_mg_l <- "<20"
Basonet_2021[!is.na(Basonet_2021$Mg_mg_l) & Basonet_2021$Mg_mg_l != "<20", ]$Mg_ppm <-
as.numeric(Basonet_2021[!is.na(Basonet_2021$Mg_mg_l) & Basonet_2021$Mg_mg_l != "<20", ]$Mg_mg_l) /
Basonet_2021[!is.na(Basonet_2021$Mg_mg_l) & Basonet_2021$Mg_mg_l != "<20", ]$Bulk_Density
summary(Basonet_2021$K_mg_l) ### 48 NAs but no characters
Basonet_2021$K_ppm <- NA
Basonet_2021[!is.na(Basonet_2021$K_mg_l),]$K_ppm <-
Basonet_2021[!is.na(Basonet_2021$K_mg_l),]$K_mg_l /
Basonet_2021[!is.na(Basonet_2021$K_mg_l),]$Bulk_Density
table(Basonet_2021$Na_mg_l) ## 565 as "<20" I wonder if set that to 0 or leave as NA
Basonet_2021$Na_ppm <- NA
Basonet_2021[Basonet_2021$Na_mg_l == "< 20", ]$Na_mg_l <- "<20"
Basonet_2021[!is.na(Basonet_2021$Na_mg_l) & Basonet_2021$Na_mg_l != "<20", ]$Na_ppm <-
as.numeric(Basonet_2021[!is.na(Basonet_2021$Na_mg_l) & Basonet_2021$Na_mg_l != "<20", ]$Na_mg_l) /
Basonet_2021[!is.na(Basonet_2021$Na_mg_l) & Basonet_2021$Na_mg_l != "<20", ]$Bulk_Density
summary(as.numeric(Basonet_2021[!is.na(Basonet_2021$Na_mg_l) & Basonet_2021$Na_mg_l != "<20", ]$Na_mg_l))
hist(as.numeric(Basonet_2021[!is.na(Basonet_2021$Na_mg_l) &
Basonet_2021$Na_mg_l != "<20", ]$Na_mg_l),
breaks=100,
xlab="Na mg/l", xlim=c(0,100))
hist(Basonet_2021$Na_ppm, breaks=100)
summary(Basonet_2021$Na_ppm)
# "P_HCl_mg-l"
table(Basonet_2021$`P_HCl_mg-l`) ### I assign NA to those below limit detection and the max value to those >120
### Or should I assign 0?
### I assign NA to those below detection limit (again, different from previous version)
Basonet_2021$P_HCl_ppm <- NA
Basonet_2021[Basonet_2021$`P_HCl_mg-l` == "<4,8",]$`P_HCl_mg-l` <- "<4.8"
Basonet_2021[Basonet_2021$`P_HCl_mg-l` == ">120",]$`P_HCl_mg-l` <- "120"
Basonet_2021[Basonet_2021$`P_HCl_mg-l` != "<4.8",]$P_HCl_ppm <-
as.numeric(Basonet_2021[Basonet_2021$`P_HCl_mg-l` != "<4.8",]$`P_HCl_mg-l`)/
Basonet_2021[Basonet_2021$`P_HCl_mg-l` != "<4.8",]$Bulk_Density
#Basonet_2021[Basonet_2021$`P_HCl_mg-l` == "<4.8",]$P_HCl_ppm <- 0
summary(Basonet_2021$P_HCl_ppm)
# "P_Olsen_mg-l"
### Phosphorus from mg/l to ... again, assign NA to those values below detection limit
### I assign NA to those below detection limit (again, different from previous version)
table(Basonet_2021$`P_Olsen_mg-l`)
Basonet_2021$P_ppm <- NA
Basonet_2021[Basonet_2021$`P_Olsen_mg-l` == "<4,8",]$`P_Olsen_mg-l` <- "<4.8"
Basonet_2021[Basonet_2021$`P_Olsen_mg-l` != "<4.8",]$P_ppm <-
as.numeric(Basonet_2021[Basonet_2021$`P_Olsen_mg-l` != "<4.8",]$`P_Olsen_mg-l`)/
Basonet_2021[Basonet_2021$`P_Olsen_mg-l` != "<4.8",]$Bulk_Density
#Basonet_2021[Basonet_2021$`P_Olsen_mg-l` == "<4.8",]$P_ppm <- 0
summary(Basonet_2021$P_ppm)
### Join texture from year 2001
colnames(Basonet_2021)[colnames(Basonet_2021) %in% colnames(Basonet_Texture_2001)]
table(Basonet_Texture_2001$Lower_limit)
#Basonet_2021 <- left_join(Basonet_2021, Basonet_Texture_2001, by= c("th","Plot","Lower_limit"))
#
# Warning message:
# In left_join(Basonet_2021, Basonet_Texture_2001, by = c("th", "Plot", :
# Detected an unexpected many-to-many relationship between `x` and `y`.
# ℹ Row 198 of `x` matches multiple rows in `y`.
# ℹ Row 214 of `y` matches multiple rows in `x`.
# ℹ If a many-to-many relationship is expected, set `relationship = "many-to-many"` to silence this warning.
### There are a couple of mistatches
as.data.frame(Basonet_2021[198,])
Basonet_Texture_2001[Basonet_Texture_2001$th==1 & Basonet_Texture_2001$Plot==1198 & Basonet_Texture_2001$Lower_limit== 20,]
Basonet_Texture_2001[214,]
Basonet_2021[Basonet_2021$th==1 & Basonet_2021$Plot==1198 & Basonet_2021$Lower_limit== 20,]
### Only one record for Basonet_Texture_2001[214,]
### Calculate average value and substitute
Basonet_Texture_2001[Basonet_Texture_2001$th==1 & Basonet_Texture_2001$Plot==1198 & Basonet_Texture_2001$Lower_limit== 20,] %>%
group_by(., th, Plot, Lower_limit) %>%
summarise(across(where(is.numeric), ~ mean(.x, na.rm = TRUE)))
### I use a new dataframe
Basonet_Texture_2001_av <- Basonet_Texture_2001 %>%
group_by(., th, Plot, Lower_limit) %>%
summarise(across(where(is.numeric), ~ mean(.x, na.rm = TRUE)))
Basonet_Texture_2001[Basonet_Texture_2001$th==1 &
Basonet_Texture_2001$Plot==1198 &
Basonet_Texture_2001$Lower_limit== 20,]
Basonet_Texture_2001_av[Basonet_Texture_2001_av$th==1 &
Basonet_Texture_2001_av$Plot==1198 &
Basonet_Texture_2001_av$Lower_limit== 20,]
### Join with average texture
Basonet_2021 <- left_join(Basonet_2021, Basonet_Texture_2001_av, by= c("th","Plot","Lower_limit"))
### Transform to spatial
### Seems that BASONET 2021 was in ETRS89 UTM30 --> epsg:25830
basonet_2021_sf <- st_as_sf(Basonet_2021, coords = c("UTM_X","UTM_Y"), crs = 25830)
#basonet_2021_sf1 <- st_as_sf(Basonet_2021, coords = c("UTM_X","UTM_Y"), crs = 25830)
#basonet_2021_sf <- st_as_sf(Basonet_2021, coords = c("UTM_X","UTM_Y"), crs = 23030)
plot(basonet_2021_sf["TOC"])
### Project
#basonet_2021_WGS84_1 <- st_transform(basonet_2021_sf1, 4326)
basonet_2021_WGS84 <- st_transform(basonet_2021_sf, 4326)
tm_shape(eus_buffer_WGS84, bbox=st_bbox(eus_buffer_WGS84), crs=4326) +
tm_borders()
tm_grid(lines=FALSE) +
tm_shape(basonet_2021_WGS84) +
tm_symbols(shape=19,
size=0.3,
legend.shape.show = TRUE,
border.col="black",
title.shape = "ED50") +
# tm_shape(basonet_2021_WGS84_1) +
# tm_symbols(shape=1,
# size=0.3,
# legend.shape.show = TRUE,
# border.col="red",
# title.shape = "ETRS89") +
tm_layout(inner.margins = c(0,0,0,0),
legend.outside=TRUE,
legend.outside.position="right",
legend.title.size=1.2,
legend.text.size=0.8)
coords_wgs84 <- st_coordinates(basonet_2021_WGS84)
Basonet_2021$Latitude <- coords_wgs84[,2]
Basonet_2021$Longitude <- coords_wgs84[,1]
rm(basonet_2021_WGS84, coords_wgs84)
tm_shape(world_eus, bbox=st_bbox(bbox_plot_Eus), crs=25830) +
tm_borders() +
tm_shape(autonomias25830) +
#tm_fill(col="gray95") +
tm_borders() +
tm_grid(lines=FALSE) +
tm_shape(basonet_2021_sf) +
tm_symbols(shape=21,
size=0.3,
legend.shape.show = TRUE,
col="Mg_ppm",
palette="viridis",
border.col="black",
title.shape = "BASONET") +
tm_layout(inner.margins = c(0,0,0,0),
legend.outside=TRUE,
legend.outside.position="right",
legend.title.size=1.2,
legend.text.size=0.8)
### "Bulk_Density" - Lab method defined as "weight of 20 cm3 of soil"
### Include information about bulk density method
### Indicate information on Bulk Density method
Basonet_2021$BD_method <- "Disturbed sample fine fraction"
Basonet_2021$BD_quality <- "Unacceptable"
### Here for BASONET 2021 unless I find I need to correct something else
### BASONET 2021
sel.columns.basonet2021 <- c("Dataset","myID","UTM_X","UTM_Y","Longitude","Latitude",
"Upper_limit","Lower_limit","Date",
#"Bulk_Density","BD_method","BD_quality",
"Sand","Silt","Clay","OM","TOC", ### Minimum dataset
"pH","EC","TN_ppm","C_N",
"P_ppm","K_ppm","Ca_ppm","Mg_ppm","Na_ppm",
"Ex_Acidity","CECef","Al_CECef",
"Carbonates","P_HCl_ppm")
Basonet_2021_m <- Basonet_2021[,sel.columns.basonet2021]
# 3.2 BASONET 2001 --------------------------------------------------------
Basonet_2001 <- read_excel("C:/Users/mercedes.roman/Desktop/SELVANS/WP1/Soil_data/Basonet/BasonetSuelos_mrd.xlsx",
sheet = "medicion2001")
Basonet_Texture_2001 <- read_excel("C:/Users/mercedes.roman/Desktop/SELVANS/WP1/Soil_data/Basonet/BasonetSuelos_mrd.xlsx",
sheet = "texturas2001")
colnames(Basonet_2001)
### Variables of interest
# "UTM_X"
# "UTM_Y"
# "Plot"
# "Lower_limit" Lower horizon limit (0 cm or 20 cm)
# "pH" pH (1:2.5 V/V) - Water extraction (ratio 1:2.5 v/v) with a pH-m - Leave as is
# "Carbonates" % CaCO3 (Bernards calcimeter). It is only analyzed in samples with pH>7.5 Volume of CO2 released when adding 50% HCl. (Bernard's calcimeter)
# "Act_Carbonate_perc" Active carbonates (%)
# "OM" Oxidised Organic Matter (%)- Oxidation of organic matter with 1N potassium dichromate and concentrated sulfuric acid. Titration with Mohr's Salt 0.5N. (Walkley-Black Method)
# "N_perc" Nitrogen Kjeldahl (%) - Digestion in sulfuric acid and subsequent distillation in basic medium. The distillate is collected in ammonia fixing solution and titrated with 0.1N HCl.
# "C_N" Ratio C to N
# "P_Olsen_ppm" Bicarbonate extractable phosphorus (mg/l) - Extraction in 0.5N sodium bicarbonate (extraction ratio 1:20 v/v)-UV-VIS spectrophotometer
# "P_HCl_ppm" Phosphorus extracted in 3% HCl (mg/l) - Extraction in 3% HCl (extraction ratio 1:20 v/v) UV-VIS spectrophotometer
# "K_ppm" Extractable Calcium, Magnesium, Pottasium, and Sodium in Ammonium acetate (ppm) Extraction in 1N ammonium acetate (extraction ratio 1:20 v/v) OPTICAL ICP
# "Ca_ppm"
# "Mg_ppm"
### Harmonise variables to same units as CARBOSOL
### Indicate dataset
Basonet_2001$Dataset <- "BASONET"
# ### Create my ID
# Basonet_2001$myID <- paste0(Basonet_2001$Dataset,"_",Basonet_2001$Plot)
### Create my ID
Basonet_2001$myID <- paste0(Basonet_2001$Dataset,"_",Basonet_2001$th,"_",Basonet_2001$Plot)
### Indicate date
Basonet_2001$Date <- 2001
### Horizon limits
table(Basonet_2001$Lower_limit)
Basonet_2001$Upper_limit <- NA
Basonet_2001$Upper_limit <- ifelse(Basonet_2001$Lower_limit == 20, 0,
ifelse(Basonet_2001$Lower_limit == 40, 20, NA))
### Variables in BASONET 2001 - same as CARBOSOL
### pH
summary(Basonet_2001$pH)
### "Bulk_Density" - Lab method defined as "weight of 10 cm3 of soil"
### Indicate information on Bulk Density method
Basonet_2001$BD_method <- "Disturbed sample fine fraction"
Basonet_2001$BD_quality <- "Unacceptable"
# "Carbonates" Only analysed in samples with pH>7.5. CO2 volume released when adding HCl 50% (Bernard calcimeter)
table(Basonet_2001$Carbonates)
Basonet_2001[Basonet_2001$pH <= 7.5,]$Carbonates
Basonet_2001[Basonet_2001$pH > 7.5,]$Carbonates
summary(Basonet_2001[is.na(Basonet_2001$Carbonates),]$pH)
Basonet_2001[Basonet_2001$Carbonates == "-", ]$pH
### Assign carbonates == 0 % for pH < 7.5
Basonet_2001[Basonet_2001$pH <= 7.5 & is.na(Basonet_2001$Carbonates),]$Carbonates <- 0
### Assign carbonates == 0 % for pH > 7.5 and NA
Basonet_2001[Basonet_2001$pH > 7.5 & is.na(Basonet_2001$Carbonates),]$Carbonates <- 0
# ### when carbonates "<1" I assign 0 %
# Basonet_2001[Basonet_2001$Carbonates == "<1",]$Carbonates <- "0"
# OM is in % as in Carbosol
# Conversion into TOC in %
Basonet_2001$TOC <- NA
Basonet_2001$TOC <- Basonet_2001$OM / 1.724
# [16] "N_perc"
### TN from % to ppm
Basonet_2001$TN_ppm <-NA
Basonet_2001$TN_ppm <- Basonet_2001$N_perc * 10000
# "C_N" as it is
# "Ca_ppm" exists
# "K_ppm" exists
# "Mg_ppm" exists
# "Na_ppm" not measured
### P_Olsen_ppm
### P_HCl_ppm
### Join with average texture from year 2001
Basonet_2001 <- left_join(Basonet_2001, Basonet_Texture_2001_av, by= c("th","Plot","Lower_limit"))
### Rename Active carbonates column
summary(Basonet_2001$Act_Carbonate_perc)
colnames(Basonet_2001)[colnames(Basonet_2001) == "Act_Carbonate_perc"] <- "Act_carbonates"
colnames(Basonet_2001)[colnames(Basonet_2001) =="P_Olsen_ppm"] <- "P_ppm"
### Transform to spatial
### It seems in 2001 the datum was ED50
basonet_2001_sf <- st_as_sf(Basonet_2001, coords = c("UTM_X","UTM_Y"), crs = 23030)
#basonet_2001_sf <- st_as_sf(Basonet_2001, coords = c("UTM_X","UTM_Y"), crs = 25830)
### Latitude and longitude
basonet_2001_WGS84 <- st_transform(basonet_2001_sf, 4326)
coords_wgs84 <- st_coordinates(basonet_2001_WGS84)
Basonet_2001$Latitude <- coords_wgs84[,2]
Basonet_2001$Longitude <- coords_wgs84[,1]
### Transform to ETRS89
st_can_transform(23030,25830) # TRUE
basonet_2001_sf <- st_transform(basonet_2001_sf, 25830)
plot(basonet_2001_sf["TOC"])
tm_shape(world_eus, bbox=st_bbox(euskadi), crs=25830) +
tm_borders() +
tm_shape(autonomias25830) +
tm_fill(col="gray95") +
tm_borders() +
tm_grid(lines=FALSE) +
tm_shape(basonet_2001_sf) +
tm_symbols(shape=21,
size=0.3,
legend.shape.show = TRUE,
col="C_N",
palette="viridis",
border.col="black",
title.shape = "BASONET") +
tm_layout(inner.margins = c(0,0,0,0),
legend.outside=TRUE,
legend.outside.position="right",
legend.title.size=1.2,
legend.text.size=0.8)
rm(basonet_2001_WGS84, coords_wgs84, basonet_2001_sf)
### Here for BASONET 2001 unless I find I need to correct something else
# 3.3 BASONET Bulk Density 2001 -------------------------------------------
setwd("C:/Users/mercedes.roman/Desktop/SELVANS/WP1/Soil_data/Basonet/")
### Join with Bulk Density from cylinder...
BasonetDens01 <- read_excel("BasonetDens01.xlsx", sheet = "DensAparCilindros2001")
colnames(BasonetDens01)[colnames(BasonetDens01)== "TH"] <- "th"
colnames(BasonetDens01)[colnames(BasonetDens01)== "Horiz"] <- "Lower_limit"
colnames(BasonetDens01)[colnames(BasonetDens01)== "Parcela"] <- "Plot"
### Average by horizon - three cores were sampled by horizon
BasonetDensAve <- BasonetDens01 %>%
group_by(., th, Plot, Lower_limit) %>%
summarise(., Bulk_Density_Cylinder = mean(DensApar, na.rm = TRUE))
### Join with all data from 2001
colnames(Basonet_2001)[colnames(Basonet_2001) %in% colnames(BasonetDensAve)]
Basonet_2001 <- left_join(Basonet_2001, BasonetDensAve, by= c("th","Plot","Lower_limit"))
BD_df <- Basonet_2001[,c("UTM_X","UTM_Y","th","Plot","Lower_limit",
"Bulk_Density_Cylinder","TOC","Clay","Silt","Sand")]
### In fact, I am going to replace the bulk density with the right bulk density values
plot(Basonet_2001$Bulk_Density, Basonet_2001$Bulk_Density_Cylinder)
abline(0,1)
Basonet_2001$Bulk_Density <- NA
Basonet_2001$Bulk_Density <- Basonet_2001$Bulk_Density_Cylinder
Basonet_2001$BD_method <- "Core method"
Basonet_2001$BD_quality <- "medium"
### BASONET 2001
sel.columns.basonet2001 <- c("Dataset","myID","UTM_X","UTM_Y","Longitude","Latitude",
"Upper_limit","Lower_limit","Date",
"Bulk_Density","BD_method","BD_quality",
"Sand","Silt","Clay","OM","TOC", ### Minimum dataset
"pH","TN_ppm","C_N",
"P_ppm","K_ppm","Ca_ppm","Mg_ppm",
"Carbonates","Act_carbonates",
"P_HCl_ppm")
Basonet_2001_m <- Basonet_2001[,sel.columns.basonet2001]
# 4.1 LUCAS 2018 ----------------------------------------------------------
setwd("C:/Users/mercedes.roman/Desktop/SELVANS/WP1/Soil_data/LUCAS_2018")
library(readr)
BulkDensity_2018_final_2 <- read_csv("LUCAS-SOIL-2018-v2/BulkDensity_2018_final-2.csv")
LUCAS_SOIL_2018 <- read_csv("LUCAS-SOIL-2018-v2/LUCAS-SOIL-2018.csv")
### Attach the locations (real) from microdata
microdata_lucas2018 <- read_csv("LUCAS-SOIL-2018-v2/ES_2018_20200213.csv")
### Transform Bulk Density to long
colnames(BulkDensity_2018_final_2) <- c("POINTID","0-10 cm","10-20 cm","20-30 cm","0-20 cm")
BulkDensity_2018_long <- BulkDensity_2018_final_2 %>%
as.data.frame(.,) %>%
pivot_longer(-c(POINTID), names_to = "Depth", values_to = "Bulk_Density")
### Separate 20-30 cm soil data
lucas_20_30 <- LUCAS_SOIL_2018 %>%
select(., c("POINTID", "OC (20-30 cm)", "CaCO3 (20-30 cm)")) %>%
filter(., !is.na(`OC (20-30 cm)`)) %>%
mutate(., "Depth" = "20-30 cm")
colnames(lucas_20_30) <- c("POINTID","OC","CaCO3","Depth")
lucas_20_30$OC <- as.character(lucas_20_30$OC)
lucas_20_30$CaCO3 <- as.character(lucas_20_30$CaCO3)
sel_cols <- colnames(LUCAS_SOIL_2018)[!colnames(LUCAS_SOIL_2018) %in% c("OC (20-30 cm)","CaCO3 (20-30 cm)")]
LUCAS_SOIL_2018 <- LUCAS_SOIL_2018[,sel_cols]
### I subset only data from Spain
LUCAS_SOIL_2018 <- LUCAS_SOIL_2018[LUCAS_SOIL_2018$NUTS_0 == "ES", ]
### subset 20-30 cm observations in the locations from Spain
lucas_20_30 <- lucas_20_30[lucas_20_30$POINTID %in% LUCAS_SOIL_2018$POINTID,]
### None present
### Join soil data and bulk density
LUCAS_2018 <- left_join(LUCAS_SOIL_2018, BulkDensity_2018_long)
### Change name
colnames(microdata_lucas2018)[colnames(microdata_lucas2018)=="POINT_ID"] <- "POINTID"
### What columns are the same?
colnames(microdata_lucas2018)[colnames(microdata_lucas2018) %in% colnames(LUCAS_SOIL_2018)]
### SURVEY_DATE has a different format in both dataframes so I don´t keep it
### Only columns I want to use
sel_microdata <- c("POINTID","GPS_LONG","GPS_LAT")
### Add real coordinates
microdata_lucas2018[,sel_microdata]
### Transform POINTID to numeric
microdata_lucas2018$POINTID <- as.numeric(microdata_lucas2018$POINTID)
### Add real coordinates
LUCAS_2018 <- left_join(LUCAS_2018, microdata_lucas2018[,sel_microdata])
### Exclude points without real coordinates
LUCAS_2018 <- LUCAS_2018[LUCAS_2018$GPS_LAT != 88.888888,]
LUCAS_2018 <- LUCAS_2018[!is.na(LUCAS_2018$GPS_LAT),]
### Correct the Latitude to negative where it corresponds (comparison theoretical with recorded GPS coordinates)
LUCAS_2018$GPS_LONG <- ifelse(LUCAS_2018$TH_LONG >= 0, yes=LUCAS_2018$GPS_LONG, no = - LUCAS_2018$GPS_LONG)
LUCAS_2018$Longitude <- LUCAS_2018$GPS_LONG
LUCAS_2018$Latitude <- LUCAS_2018$GPS_LAT
### Assign CRS to LUCAS (theoretical coordinates. Real ones are in EUROSTAT microdata)
### Transform to spatial
LUCAS_2018_sf <- st_as_sf(LUCAS_2018, coords = c("GPS_LONG","GPS_LAT"), crs = 4326)
plot(LUCAS_2018_sf["Bulk_Density"])
LUCAS_2018_sf <- st_transform(LUCAS_2018_sf,25830)
### Intersection with Euskadi
LUCAS_2018_Eus <- st_intersection(LUCAS_2018_sf, euskadi)
### 38 observations
tm_shape(world_eus, bbox=st_bbox(euskadi), crs=25830) +
tm_borders() +
tm_shape(autonomias25830) +
tm_fill(col="gray95") +
tm_borders() +
tm_grid(lines=FALSE) +
tm_shape(LUCAS_2018_Eus) +
tm_symbols(shape=21,
size=0.3,
legend.shape.show = TRUE,
col="Bulk_Density",
palette="viridis",
border.col="black",
title.shape = "BASONET") +
tm_layout(inner.margins = c(0,0,0,0),
legend.outside=TRUE,
legend.outside.position="right",
legend.title.size=1.2,
legend.text.size=0.8)
tm_shape(autonomias25830) +
tm_fill(col="gray95") +
tm_borders() +
tm_grid(lines=FALSE) +
tm_shape(LUCAS_2018_sf) +
tm_symbols(shape=21,
size=0.3,
legend.shape.show = TRUE,
col="Bulk_Density",
palette="viridis",
border.col="black",
title.shape = "BASONET") +
tm_layout(inner.margins = c(0,0,0,0),
legend.outside=TRUE,
legend.outside.position="right",
legend.title.size=1.2,
legend.text.size=0.8)
### Drop the geometry. Back to dataframe
LUCAS_2018_Eus_df <- LUCAS_2018_Eus
coords_lucas_utm <- st_coordinates(LUCAS_2018_Eus)
LUCAS_2018_Eus_df$UTM_X <- coords_lucas_utm[,1]
LUCAS_2018_Eus_df$UTM_Y <- coords_lucas_utm[,2]
LUCAS_2018_Eus_df <- as.data.frame(LUCAS_2018_Eus_df)
### Add info on sampling year in a new column "Date"