generated from theamarks/R-analysis-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.Rhistory
512 lines (512 loc) · 20.9 KB
/
.Rhistory
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
commercial_gbif %>%
filter(accepted %in% commercial_products$sciname_joinable_to_fishbase) %>%
select(accepted, family, order, class),
by = c("sciname_joinable_to_fishbase" = "accepted")
)
commercial_gbif %>%
filter(accepted %in% commercial_products$sciname_joinable_to_fishbase)
commercial_gbif
commercial_gbif <- commercial_gbif %>%
filter(accepted %in% commercial_products$sciname_joinable_to_fishbase)
commercial_gbif
commercial_products %>%
commercial_products %>%
commercial_products <- commercial_products %>%
mutate(
species = TrueSpecies,
genus = Genus,
across(
c(family, order, class),
~ map_chr(sciname_joinable_to_fishbase, ~ {
result <- commercial_gbif %>%
filter(str_detect(accepted, .x)) %>%
count(.x) %>%
arrange(.x) %>%
drop_na() %>%
pull(.x) # Pull the respective column based on the target
if (length(result) > 0) result[1] else NA_character_
})
)) %>%
select(-c(TrueSpecies, Genus))
names(commercial_products)
commercial_products
commercial_gbif %>%
filter(str_detect(accepted, "Abalistes stellatus")) %>%
count(accepted) %>% # Count occurrences of each accepted name
arrange(desc(n))
commercial_gbif %>%
filter(str_detect(accepted, "Abalistes stellatus")) %>%
count(genus) %>% # Count occurrences of each accepted name
arrange(desc(n))
names(commercial_products)
commercial_products
commercial_gbif %>%
filter(str_detect(accepted, "Abramis brama")) %>%
count(genus) %>% # Count occurrences of each accepted name
arrange(desc(n)) %>% # Arrange by count (descending)
drop_na() %>%
pull(genus)
commercial_gbif %>%
filter(str_detect(accepted, "Abramis brama")) %>%
count(genus) %>% # Count occurrences of each accepted name
arrange(desc(n))
commercial_products
commercial_gbif %>%
filter(str_detect(accepted, "Abudefduf vaigiensis")) %>%
count(genus) %>% # Count occurrences of each accepted name
arrange(desc(n)) %>% # Arrange by count (descending)
drop_na() %>%
pull(genus)
commercial_gbif %>%
filter(str_detect(accepted, "Abudefduf vaigiensis")) %>%
count(genus) %>% # Count occurrences of each accepted name
arrange(desc(n))
commercial_gbif %>%
count(accepted)
commercial_gbif %>%
count(accepted) %>%
arrange(-n)
commercial_gbif %>%
filter(str_detect(accepted, "Abudefduf vaigiensis")) %>%
count(genus) %>% # Count occurrences of each accepted name
arrange(desc(n)) %>% # Arrange by count (descending)
drop_na() %>%
pull(genus)
commercial_gbif %>%
count(accepted) %>%
arrange(-n) %>%
drop_na() %>%
pull(accepted)
commercial_products <- commercial_products %>%
mutate(
species = TrueSpecies,
genus = Genus,
# Apply across to mutate multiple columns (family, order, class)
family = map_chr(sciname_joinable_to_fishbase, ~ {
result <- commercial_gbif %>%
filter(str_detect(accepted, .x)) %>%
count(family) %>% # Count occurrences of each accepted name
arrange(desc(n)) %>% # Arrange by count (descending)
drop_na() %>%
pull(family) # Pull the family column after filtering and processing
if (length(result) > 0) result[1] else NA_character_ # Return first result or NA
}),
order = map_chr(sciname_joinable_to_fishbase, ~ {
result <- commercial_gbif %>%
filter(str_detect(accepted, .x)) %>%
count(order) %>%
arrange(desc(n)) %>%
drop_na() %>%
pull(order)
if (length(result) > 0) result[1] else NA_character_
}),
class = map_chr(sciname_joinable_to_fishbase, ~ {
result <- commercial_gbif %>%
filter(str_detect(accepted, .x)) %>%
count(class) %>%
arrange(desc(n)) %>%
drop_na() %>%
pull(class)
if (length(result) > 0) result[1] else NA_character_
})
) %>%
select(-c(TrueSpecies, Genus))
commercial_products
commercial_gbif %>%
filter(accepted == "Acanthurus fowleri")
commercial_products %>%
filter(accepted == "Acanthurus fowleri")
commercial_products %>%
filter(sciname_joinable_to_fishbase == "Acanthurus fowleri")
name_lookup("Acanthurus fowleri")
commercial_gbif
commercial_gbif %>%
count(accepted)
commercial_gbif %>%
count(accepted) %>%
arrange(-n)
commercial_gbif
read_parquet("../data/rgbif_data/commercial_higher_taxa_names.parquet") %>%
count(accepted) %>%
arrange(-n)
# Pull rgbif joined data with commercial species
commercial_gbif <- read_parquet("../data/rgbif_data/commercial_higher_taxa_names.parquet")
commercial_gbif
commercial_products %>%
filter(is.na(family) & !is.na(order) & !is.na(class))
commercial_products
commercial_products %>%
filter(is.na(family) & !is.na(order) & !is.na(class))
commercial_products
commercial_products %>%
filter(!is.na(family) & !is.na(order) & !is.na(class))
commercial_products <- commercial_products %>%
mutate(
species = TrueSpecies,
genus = Genus,
# Apply across to mutate multiple columns (family, order, class)
family = map_chr(sciname_joinable_to_fishbase, ~ {
result <- commercial_gbif %>%
filter(str_detect(scientificName, .x)) %>%
count(family) %>% # Count occurrences of each accepted name
arrange(desc(n)) %>% # Arrange by count (descending)
drop_na() %>%
pull(family) # Pull the family column after filtering and processing
if (length(result) > 0) result[1] else NA_character_ # Return first result or NA
}),
order = map_chr(sciname_joinable_to_fishbase, ~ {
result <- commercial_gbif %>%
filter(str_detect(scientificName, .x)) %>%
count(order) %>%
arrange(desc(n)) %>%
drop_na() %>%
pull(order)
if (length(result) > 0) result[1] else NA_character_
}),
class = map_chr(sciname_joinable_to_fishbase, ~ {
result <- commercial_gbif %>%
filter(str_detect(scientificName, .x)) %>%
count(class) %>%
arrange(desc(n)) %>%
drop_na() %>%
pull(class)
if (length(result) > 0) result[1] else NA_character_
})
) %>%
select(-c(TrueSpecies, Genus))
commercial_products
# Step 4: Join full matched species only with fb/slb species of commercial interest
commercial_products <- inner_join(pa_excluding_artis, fb_slb_commercial_interests, by = c("sciname_joinable_to_fishbase" = "Species", "countries_found" = "country")) %>%
mutate(presence_or_absence = 1) %>%
mutate(sciname = str_to_lower(sciname_joinable_to_fishbase))
commercial_products <- commercial_products %>%
mutate(
species = TrueSpecies,
genus = Genus,
# Apply across to mutate multiple columns (family, order, class)
family = map_chr(sciname_joinable_to_fishbase, ~ {
result <- commercial_gbif %>%
filter(str_detect(scientificName, .x)) %>%
count(family) %>% # Count occurrences of each accepted name
arrange(desc(n)) %>% # Arrange by count (descending)
drop_na() %>%
pull(family) # Pull the family column after filtering and processing
if (length(result) > 0) result[1] else NA_character_ # Return first result or NA
}),
order = map_chr(sciname_joinable_to_fishbase, ~ {
result <- commercial_gbif %>%
filter(str_detect(scientificName, .x)) %>%
count(order) %>%
arrange(desc(n)) %>%
drop_na() %>%
pull(order)
if (length(result) > 0) result[1] else NA_character_
}),
class = map_chr(sciname_joinable_to_fishbase, ~ {
result <- commercial_gbif %>%
filter(str_detect(scientificName, .x)) %>%
count(class) %>%
arrange(desc(n)) %>%
drop_na() %>%
pull(class)
if (length(result) > 0) result[1] else NA_character_
})
) %>%
select(-c(TrueSpecies, Genus))
commercial_products <- commercial_products %>%
mutate(
species = TrueSpecies,
genus = Genus,
# Apply across to mutate multiple columns (family, order, class)
family = map_chr(sciname_joinable_to_fishbase, ~ {
result <- commercial_gbif %>%
filter(str_detect(scientificName, .x)) %>%
count(family) %>% # Count occurrences of each accepted name
arrange(desc(n)) %>% # Arrange by count (descending)
drop_na() %>%
pull(family) # Pull the family column after filtering and processing
if (length(result) > 0) result[1] else NA_character_ # Return first result or NA
}),
order = map_chr(sciname_joinable_to_fishbase, ~ {
result <- commercial_gbif %>%
filter(str_detect(scientificName, .x)) %>%
count(order) %>%
arrange(desc(n)) %>%
drop_na() %>%
pull(order)
if (length(result) > 0) result[1] else NA_character_
}),
class = map_chr(sciname_joinable_to_fishbase, ~ {
result <- commercial_gbif %>%
filter(str_detect(scientificName, .x)) %>%
count(class) %>%
arrange(desc(n)) %>%
drop_na() %>%
pull(class)
if (length(result) > 0) result[1] else NA_character_
})
) %>%
select(-c(TrueSpecies, Genus))
commercial_products
# 3914
commercial_products %>%
filter(!is.na(family) & !is.na(order) & !is.na(class))
# 3914
commercial_products %>%
filter(!is.na(family) & !is.na(order) & !is.na(class))
inner_join(pa_excluding_artis, fb_slb_commercial_interests, by = c("sciname_joinable_to_fishbase" = "Species", "countries_found" = "country")) %>%
mutate(presence_or_absence = 1) %>%
mutate(sciname = str_to_lower(sciname_joinable_to_fishbase))
inner_join(pa_excluding_artis, fb_slb_commercial_interests, by = c("sciname_joinable_to_fishbase" = "Species", "countries_found" = "country")) %>%
mutate(presence_or_absence = 1) %>%
mutate(sciname = str_to_lower(sciname_joinable_to_fishbase)) %>%
mutate(species = TrueSpecies, genus = Genus)
inner_join(pa_excluding_artis, fb_slb_commercial_interests, by = c("sciname_joinable_to_fishbase" = "Species", "countries_found" = "country")) %>%
mutate(presence_or_absence = 1) %>%
mutate(sciname = str_to_lower(sciname_joinable_to_fishbase)) %>%
mutate(species = TrueSpecies, genus = Genus)
source("../code/test_script.Rmd")
source("code/test_script.Rmd")
source("code/test_script.R")
source("../code/test_script.Rmd")
source("code/test_script.Rmd")
file.exists("code/test_script.Rmd")
file.exists("../code/test_script.Rmd")
source("../code/test_script.Rmd")
rmarkdown::render("../code/test_script.Rmd")
knitr::opts_chunk$set(echo = TRUE)
pee = "hi"
rmarkdown::render("../code/test_script.Rmd")
print(poo)
rmarkdown::render("../code/test_script.Rmd")
# Step 4: Join full matched species only with fb/slb species of commercial interest
commercial_products <- inner_join(pa_excluding_artis, fb_slb_commercial_interests, by = c("sciname_joinable_to_fishbase" = "Species", "countries_found" = "country")) %>%
mutate(presence_or_absence = 1) %>%
mutate(sciname = str_to_lower(sciname_joinable_to_fishbase))
commercial_products
# Helper function to get the most frequent taxonomy value
get_taxonomy_value <- function(sciname, column_name, gbif_data) {
result <- gbif_data %>%
filter(str_detect(scientificName, sciname)) %>%
count(!!sym(column_name)) %>%
arrange(desc(n)) %>%
drop_na() %>%
pull(!!sym(column_name))
if (length(result) > 0) result[1] else NA_character_
}
# Apply across family, order, and class in a more efficient way
commercial_products <- commercial_products %>%
mutate(
species = TrueSpecies,
genus = Genus,
# Use map to apply the helper function to multiple taxonomy columns
family = map_chr(sciname_joinable_to_fishbase, ~ get_taxonomy_value(.x, "family", commercial_gbif)),
order = map_chr(sciname_joinable_to_fishbase, ~ get_taxonomy_value(.x, "order", commercial_gbif)),
class = map_chr(sciname_joinable_to_fishbase, ~ get_taxonomy_value(.x, "class", commercial_gbif))
) %>%
select(-c(TrueSpecies, Genus))
commercial_products
knitr::opts_chunk$set(echo = TRUE)
file.exists("../data/fb_slb_data")
file.exists("../data/fb_slb_datad")
file.exists("../data/fb_slb_data")
file.exists("../data/fb_slb_data/")
if (!file.exists("../data/fb_slb_data/"))
!file.exists("../data/fb_slb_data/")
!file.exists("../data/fb_slb_data/")
file.exists("../data/rgbif_data/commercial_higher_taxa_names.parquet")
commercial_products
# Step 4: Join full matched species only with fb/slb species of commercial interest
commercial_products <- inner_join(pa_excluding_artis, fb_slb_commercial_interests, by = c("sciname_joinable_to_fishbase" = "Species", "countries_found" = "country")) %>%
mutate(presence_or_absence = 1) %>%
mutate(sciname = str_to_lower(sciname_joinable_to_fishbase))
commercial_products
if (file.exists("../data/rgbif_data/commercial_products.parquet"))
file.exists("../data/rgbif_data/commercial_products.parquet")
file.exists("../data/rgbif_data/commercial_products.parquet")
!file.exists("../data/rgbif_data/commercial_products.parquet")
!file.exists("../data/rgbif_data/commercial_higher_taxa_names.parquet")
# Step 4: Join full matched species only with fb/slb species of commercial interest
commercial_products <- inner_join(pa_excluding_artis, fb_slb_commercial_interests, by = c("sciname_joinable_to_fishbase" = "Species", "countries_found" = "country")) %>%
mutate(presence_or_absence = 1) %>%
mutate(sciname = str_to_lower(sciname_joinable_to_fishbase))
# commercial_products is fed through this script (takes awhile hence in other script)
rmarkdown::render("../code/QuirozConnor_SGL_Obtain_gbif_Data.Rmd")
commercial_products
write_parquet("../data/rgbif_data/commercial_products.parquet")
write_parquet
write_parquet(commercial_products, "../data/rgbif_data/commercial_products.parquet")
!file.exists("../data/rgbif_data/commercial_products.parquet")
commercial_products
pa_excluding_artis <- read_parquet("../data/rgbif_data/commercial_products.parquet")
pa_excluding_artis
merged_presence_absence_data_country
names(merged_presence_absence_data_country)
names(pa_excluding_arits)
pa_excluding_artis <- read_parquet("../data/rgbif_data/commercial_products.parquet")
names(merged_presence_absence_data_country)
names(pa_excluding_artis)
bind_rows(pa_only_artis, pa_excluding_artis)
pa_only_artis <- bind_rows(pa_only_artis, pa_excluding_artis)
presence_absence_data_country_all_taxa <- data.frame()
for (i in unique(pa_only_artis$eez_iso3c)) {
# Group data by eez country
sliced_data <- pa_only_artis %>%
filter(eez_iso3c == sym(i))
# Create updated presence on sliced data
sliced_data_for_merging <- sliced_data %>%
mutate(unique_vals = str_replace_all(paste0(filter(., presence_or_absence == 1) %>% select(sciname, species, genus, subfamily, family, order, class, superclass, phylum, kingdom) %>%
unlist() %>%
unique(), collapse = " "), "[A-Z]", ""), presence_or_absence_all_taxa = case_when(str_detect(unique_vals, sciname) ~ 1, TRUE ~ 0))
# Combine rows of each country
presence_absence_data_country_all_taxa <- bind_rows(presence_absence_data_country_all_taxa, sliced_data_for_merging)
}
unique(pa_only_artis$eez_iso3c)
presence_absence_data_country_all_taxa
pa_only_artis <- bind_rows(pa_only_artis, pa_excluding_artis)
presence_absence_data_country_all_taxa <- data.frame()
for (i in unique(pa_only_artis$eez_iso3c)) {
# Group data by eez country
sliced_data <- pa_only_artis %>%
filter(eez_iso3c == i)
# Create updated presence on sliced data
sliced_data_for_merging <- sliced_data %>%
mutate(unique_vals = str_replace_all(paste0(filter(., presence_or_absence == 1) %>% select(sciname, species, genus, subfamily, family, order, class, superclass, phylum, kingdom) %>%
unlist() %>%
unique(), collapse = " "), "[A-Z]", ""), presence_or_absence_all_taxa = case_when(str_detect(unique_vals, sciname) ~ 1, TRUE ~ 0))
# Combine rows of each country
presence_absence_data_country_all_taxa <- bind_rows(presence_absence_data_country_all_taxa, sliced_data_for_merging)
}
# Count Number of presences/absences in filled in presence data
presence_absence_data_country_all_taxa <- presence_absence_data_country_all_taxa %>%
relocate(presence_or_absence_all_taxa, .after = presence_or_absence)
presence_absence_data_country_all_taxa %%>
presence_absence_data_country_all_taxa %>%
count(presence_or_absence_all_taxa)
commercial_products
commercial_products %>%
mutate(genus = str_to_lower(genus),
family = str_to_lower(family),
order = str_to_lower(order),
class = str_to_lower(class),
phylum = str_to_lower(phylum),
kingdom = str_to_lower(kingdom))
commercial_products <- commercial_products %>%
mutate(genus = str_to_lower(genus),
family = str_to_lower(family),
order = str_to_lower(order),
class = str_to_lower(class),
phylum = str_to_lower(phylum),
kingdom = str_to_lower(kingdom))
write_parquet(commercial_products, "../data/rgbif_data/commercial_products.parquet")
pa_excluding_artis <- read_parquet("../data/rgbif_data/commercial_products.parquet")
pa_excluding_artis
only_artis_1 <- merged_presence_absence_data_country %>%
filter(joined %in% c("only in artis", "both"))
only_artis_1
pa_only_artis
pa_excluding_artis
presence_absence_data_country_all_taxa %>%
count(presence_or_absence_all_taxa)
```
pa_excluding_artis
pa_excluding_artis %>% distinct(sciname_joinable_to_fishbase)
only_artis_1 <- merged_presence_absence_data_country %>%
filter(joined %in% c("only in artis", "both"))
pa_only_artis <- bind_rows(only_artis_1, pa_excluding_artis)
presence_absence_data_country_all_taxa <- data.frame()
for (i in unique(pa_only_artis$eez_iso3c)) {
# Group data by eez country
sliced_data <- pa_only_artis %>%
filter(eez_iso3c == i)
# Create updated presence on sliced data
sliced_data_for_merging <- sliced_data %>%
mutate(unique_vals = str_replace_all(paste0(filter(., presence_or_absence == 1) %>% select(sciname, species, genus, subfamily, family, order, class, superclass, phylum, kingdom) %>%
unlist() %>%
unique(), collapse = " "), "[A-Z]", ""), presence_or_absence_all_taxa = case_when(str_detect(unique_vals, sciname) ~ 1, TRUE ~ 0))
# Combine rows of each country
presence_absence_data_country_all_taxa <- bind_rows(presence_absence_data_country_all_taxa, sliced_data_for_merging)
}
# Count Number of presences/absences in filled in presence data
presence_absence_data_country_all_taxa <- presence_absence_data_country_all_taxa %>%
relocate(presence_or_absence_all_taxa, .after = presence_or_absence)
presence_absence_data_country_all_taxa %>%
count(presence_or_absence_all_taxa)
presence_absence_data_country_all_taxa
bind_rows(only_artis_1, pa_excluding_artis)
pa_excluding_artis
commercial_products
commercial_products %>%
mutate(eez_iso3c = countries_found) %>%
select(-countries_found)
commercial_products <- commercial_products %>%
mutate(eez_iso3c = countries_found) %>%
select(-countries_found)
write_parquet(commercial_products, "../data/rgbif_data/commercial_products.parquet")
pa_excluding_artis <- read_parquet("../data/rgbif_data/commercial_products.parquet")
pa_excluding_artis
pa_excluding_artis
only_artis_1
only_artis_1 <- merged_presence_absence_data_country %>%
filter(joined %in% c("only in artis", "both"))
pa_only_artis <- bind_rows(only_artis_1, pa_excluding_artis)
presence_absence_data_country_all_taxa <- data.frame()
for (i in unique(pa_only_artis$eez_iso3c)) {
# Group data by eez country
sliced_data <- pa_only_artis %>%
filter(eez_iso3c == i)
# Create updated presence on sliced data
sliced_data_for_merging <- sliced_data %>%
mutate(unique_vals = str_replace_all(paste0(filter(., presence_or_absence == 1) %>% select(sciname, species, genus, subfamily, family, order, class, superclass, phylum, kingdom) %>%
unlist() %>%
unique(), collapse = " "), "[A-Z]", ""), presence_or_absence_all_taxa = case_when(str_detect(unique_vals, sciname) ~ 1, TRUE ~ 0))
# Combine rows of each country
presence_absence_data_country_all_taxa <- bind_rows(presence_absence_data_country_all_taxa, sliced_data_for_merging)
}
# Count Number of presences/absences in filled in presence data
presence_absence_data_country_all_taxa <- presence_absence_data_country_all_taxa %>%
relocate(presence_or_absence_all_taxa, .after = presence_or_absence)
presence_absence_data_country_all_taxa %>%
count(presence_or_absence_all_taxa)
presence_absence_data_country_all_taxa %>%
group_by(eez_iso3c) %>%
distinct(sciname, .keep_all = TRUE) %>%
select(sciname, presence_or_absence_all_taxa) %>%
count(presence_or_absence_all_taxa) %>%
mutate(presence_or_absence_all_taxa = as.character(presence_or_absence_all_taxa)) %>%
pivot_wider(values_from = n, names_from = presence_or_absence_all_taxa, names_glue = "quantity_{presence_or_absence_all_taxa}") %>%
mutate(prop_missing = quantity_0 / (quantity_0 + quantity_1)) %>%
filter(is.na(prop_missing) & is.na(quantity_1)) %>%
rename(number_absences = "quantity_0", number_presences = "quantity_1")
prop_absences <- presence_absence_data_country_all_taxa %>%
group_by(eez_iso3c) %>%
distinct(sciname, .keep_all = TRUE) %>%
select(sciname, presence_or_absence_all_taxa) %>%
count(presence_or_absence_all_taxa) %>%
mutate(presence_or_absence_all_taxa = as.character(presence_or_absence_all_taxa)) %>%
pivot_wider(values_from = n, names_from = presence_or_absence_all_taxa, names_glue = "quantity_{presence_or_absence_all_taxa}") %>%
mutate(prop_missing = quantity_0 / (quantity_0 + quantity_1)) %>%
ggplot(aes(x = prop_missing)) +
geom_boxplot(fill = artis_palette(1)) +
labs(x = "Prop of countries' stock reported as absent\n(Fishbase/Sealifebase") +
theme_light() +
theme(axis.title.y=element_blank(),
axis.text.y=element_blank(),
axis.ticks.y=element_blank())
# Proportion of reports that are seen as countrywide absences according to fishbase/sealifebase
(prop_absences <- presence_absence_data_country_all_taxa %>%
group_by(eez_iso3c) %>%
distinct(sciname, .keep_all = TRUE) %>%
select(sciname, presence_or_absence_all_taxa) %>%
count(presence_or_absence_all_taxa) %>%
mutate(presence_or_absence_all_taxa = as.character(presence_or_absence_all_taxa)) %>%
pivot_wider(values_from = n, names_from = presence_or_absence_all_taxa, names_glue = "quantity_{presence_or_absence_all_taxa}") %>%
mutate(prop_missing = quantity_0 / (quantity_0 + quantity_1)) %>%
ggplot(aes(x = prop_missing)) +
geom_boxplot(fill = artis_palette(1)) +
labs(x = "Prop of countries' stock reported as absent\n(Fishbase/Sealifebase") +
theme_light() +
theme(axis.title.y=element_blank(),
axis.text.y=element_blank(),
axis.ticks.y=element_blank()))
ggsave("../images/prop_absences.jpg", plot = prop_absences, device = "jpeg", height = 3, width = 5, units = "in")