-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript_04_pdf_subsets.R
179 lines (154 loc) · 6.77 KB
/
script_04_pdf_subsets.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
library("tidyverse")
library("tidymodels")
library("lubridate")
library("prospectr")
library("cowplot")
library("qs")
# Mounted disk for storing big files
mnt.dir <- "~/projects/mnt-ringtrial/"
dir.preprocessed <- paste0(mnt.dir, "preprocessed/")
########################################
##### Soil Properties distribution #####
########################################
kssl.library.soil <- read_csv(paste0(dir.preprocessed, "KSSL_soilMIRspectra_SNV.csv"),
col_select = 1:10)
head(kssl.library.soil)
rt.wetchem <- read_csv(paste0(dir.preprocessed, "RT_wetchem_soildata.csv"))
rt.wetchem
sst.ids <- qread("outputs/RT_sst_ids.qs")
test.ids <- qread("outputs/RT_test_ids.qs")
# Panel carbon_org_perc
data.carbon_org_perc <- kssl.library.soil %>%
mutate(sample_id = as.character(sample_id)) %>%
select(sample_id, carbon_org_perc) %>%
filter(!is.na(carbon_org_perc)) %>%
mutate(subset = "KSSL library") %>%
bind_rows({
rt.wetchem %>%
select(sample_id, carbon_org_perc) %>%
mutate(subset = ifelse(sample_id %in% sst.ids, "RT SST", "RT test"))
}, .)
# data.carbon_org_perc %>%
# mutate(carbon_org_perc = ifelse(carbon_org_perc <= 0, 0.01, carbon_org_perc)) %>%
# mutate(carbon_org_perc = log(carbon_org_perc)) %>%
# ggplot(aes(x = carbon_org_perc, fill = subset, color = subset)) +
# geom_density(alpha = 0.15) +
# labs(y = "Density", x = "", fill = "", color = "") +
# theme_light()
p.carbon_org_perc <- data.carbon_org_perc %>%
mutate(carbon_org_perc = ifelse(carbon_org_perc <= 0, 0.01, carbon_org_perc)) %>%
mutate(carbon_org_perc = log(carbon_org_perc)) %>%
ggplot(aes(x = carbon_org_perc, fill = subset, color = subset)) +
geom_density(alpha = 0.15, show.legend = F) +
labs(y = "", x = expression(OC~('%')), fill = "", color = "") +
scale_x_continuous(breaks = c(-5, -2.5, 0, 2.5), labels = round(exp(c(-5, -2.5, 0, 2.5)), 2)) +
# scale_fill_manual(values = c("darkred", "darkblue")) +
# scale_color_manual(values = c("darkred", "darkblue")) +
annotate("text", label = "A)", x = -5.25, y = 0.50, size = 4, colour = "black") +
theme_light() +
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.text.y = element_blank(),
axis.ticks.y = element_blank())
# Panel clay_perc
data.clay_perc <- kssl.library.soil %>%
mutate(sample_id = as.character(sample_id)) %>%
select(sample_id, clay_perc) %>%
filter(!is.na(clay_perc)) %>%
mutate(subset = "KSSL library") %>%
bind_rows({
rt.wetchem %>%
select(sample_id, clay_perc) %>%
mutate(subset = ifelse(sample_id %in% sst.ids, "RT SST", "RT test"))
}, .)
# data.clay_perc %>%
# mutate(clay_perc = ifelse(clay_perc <= 0, 0.01, clay_perc)) %>%
# ggplot(aes(x = clay_perc, fill = subset, color = subset)) +
# geom_density(alpha = 0.15) +
# labs(y = "Density", x = "", fill = "", color = "") +
# theme_light()
p.clay_perc <- data.clay_perc %>%
mutate(clay_perc = ifelse(clay_perc <= 0, 0.01, clay_perc)) %>%
ggplot(aes(x = clay_perc, fill = subset, color = subset)) +
geom_density(alpha = 0.15, show.legend = T) +
labs(y = "", x = expression(Clay~('%')), fill = "", color = "") +
# scale_fill_manual(values = c("darkred", "darkblue")) +
# scale_color_manual(values = c("darkred", "darkblue")) +
annotate("text", label = "B)", x = 0, y = 0.06, size = 4, colour = "black") +
theme_light() +
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.text.y = element_blank(),
axis.ticks.y = element_blank(),
legend.position = c(0.75, 0.75))
# Panel pH_H2O
data.pH_H2O <- kssl.library.soil %>%
mutate(sample_id = as.character(sample_id)) %>%
rename(pH_H2O = pH_H20) %>%
select(sample_id, pH_H2O) %>%
filter(!is.na(pH_H2O)) %>%
mutate(subset = "KSSL library") %>%
bind_rows({
rt.wetchem %>%
rename(pH_H2O = pH_H20) %>%
select(sample_id, pH_H2O) %>%
mutate(subset = ifelse(sample_id %in% sst.ids, "RT SST", "RT test"))
}, .)
# data.pH_H2O %>%
# mutate(pH_H2O = ifelse(pH_H2O <= 0, 0.01, pH_H2O)) %>%
# ggplot(aes(x = pH_H2O, fill = subset, color = subset)) +
# geom_density(alpha = 0.15) +
# labs(y = "Density", x = "", fill = "", color = "") +
# theme_light()
p.pH_H2O <- data.pH_H2O %>%
mutate(pH_H2O = ifelse(pH_H2O <= 0, 0.01, pH_H2O)) %>%
ggplot(aes(x = pH_H2O, fill = subset, color = subset)) +
geom_density(alpha = 0.15, show.legend = F) +
labs(y = "", x = expression(pH~(H[2]*O)), fill = "", color = "") +
# scale_fill_manual(values = c("darkred", "darkblue")) +
# scale_color_manual(values = c("darkred", "darkblue")) +
annotate("text", label = "C)", x = 2, y = 0.50, size = 4, colour = "black") +
theme_light() +
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.text.y = element_blank(),
axis.ticks.y = element_blank())
# Panel potassium_cmolkg
data.potassium_cmolkg <- kssl.library.soil %>%
mutate(sample_id = as.character(sample_id)) %>%
select(sample_id, potassium_cmolkg) %>%
filter(!is.na(potassium_cmolkg)) %>%
mutate(subset = "KSSL library") %>%
bind_rows({
rt.wetchem %>%
select(sample_id, potassium_cmolkg) %>%
mutate(subset = ifelse(sample_id %in% sst.ids, "RT SST", "RT test"))
}, .)
# data.potassium_cmolkg %>%
# mutate(potassium_cmolkg = ifelse(potassium_cmolkg <= 0, 0.01, potassium_cmolkg)) %>%
# mutate(potassium_cmolkg = log(potassium_cmolkg)) %>%
# ggplot(aes(x = potassium_cmolkg, fill = subset, color = subset)) +
# geom_density(alpha = 0.15) +
# labs(y = "Density", x = "", fill = "", color = "") +
# theme_light()
p.potassium_cmolkg <- data.potassium_cmolkg %>%
mutate(potassium_cmolkg = ifelse(potassium_cmolkg <= 0, 0.01, potassium_cmolkg)) %>%
mutate(potassium_cmolkg = log(potassium_cmolkg)) %>%
ggplot(aes(x = potassium_cmolkg, fill = subset, color = subset)) +
geom_density(alpha = 0.15, show.legend = F) +
labs(y = "", x = expression(K~(cmol[c]~kg^-1)), fill = "", color = "") +
scale_x_continuous(breaks = c(-4, -2, 0, 2), labels = round(exp(c(-4, -2, 0, 2)), 2)) +
# scale_fill_manual(values = c("darkred", "darkblue")) +
# scale_color_manual(values = c("darkred", "darkblue")) +
annotate("text", label = "D)", x = -5.5, y = 0.90, size = 4, colour = "black") +
theme_light() +
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.text.y = element_blank(),
axis.ticks.y = element_blank())
# Panel combination
p.final.ver <- plot_grid(p.carbon_org_perc, p.clay_perc, p.pH_H2O, p.potassium_cmolkg,
labels = c('', '', '', ''),
ncol = 2, align = 'v', axis = 'l')
ggsave("outputs/plot_soil_properties_distribution.png", p.final.ver, dpi = 300,
width = 8, height = 6, units = "in", scale = 1)