-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path05_amphibian_trade_analyses.R
1443 lines (1174 loc) · 41.4 KB
/
05_amphibian_trade_analyses.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
library(tidyverse)
library(ggtext)
library(assertthat)
options(scipen = 10000)
#==============================================================================
# Import the full cleaned LEMIS amphibian dataset
a <- read_csv("data/cleaned/harmonized_amphibian_LEMIS_1999_to_2021.csv") %>%
# add variables for clarity
mutate(
country_origin_full =
ifelse(country_origin == "TW", "Taiwan", country_origin_full),
scientific_name = paste(genus_aw, species_aw)
) %>%
# import full port names
left_join(
.,
lemis::lemis_codes() %>%
filter(field == "port") %>%
select(-field, -post_feb_2013) %>%
rename(port = code, port_full = value),
by = "port"
)
#==============================================================================
# How many amphibian records are there overall?
nrow(a)
# How many amphibian shipments overall?
# But note that some years don't have "control_number" at all, so this is
# an underestimate of shipment numbers
n_distinct(a$control_number)
# Generate a dataset representing live amphibian imports, recorded in numbers
# of individuals
a.live <- a %>%
filter(description == "LIV", unit == "NO")
# How many live amphibian individuals are reported in the data?
a.live.individuals <- sum(a.live$quantity)
a.live.individuals
# Generate a dataset representing amphibian leg and meat imports,
# recorded in kg
a.leg.meat <- a %>%
filter(description %in% c("LEG", "MEA"), unit == "KG")
# These are exclusively anurans
table(a.leg.meat$order, useNA = "ifany")
# Subset live amphibian data down to caudates
a.live.caudates <- a.live %>%
filter(order == "Caudata")
# How many live caudate individuals are reported in the data?
sum(a.live.caudates$quantity)
#==============================================================================
# Import AmphibiaWeb taxonomy
aw.taxonomy <-
jsonlite::read_json("data/taxonomy/amphib_names.json", simplifyVector = T)
# Generate a vector of unique AmphibiaWeb genera
aw.genera <- aw.taxonomy %>%
pull(genus) %>%
unique() %>%
sort()
# Generate a vector of unique AmphibiaWeb species
aw.species <- aw.taxonomy %>%
mutate(scientific_name = paste(genus, species)) %>%
pull(scientific_name) %>%
unique() %>%
sort()
# How many AmphibiaWeb species are in the full LEMIS amphibian dataset?
sum(unique(a$scientific_name) %in% aw.species)
# What percentage of the dataset has good scientific names and good generic
# names?
# Good names down to species
sum(a$scientific_name %in% aw.species)/nrow(a)
# Proportion of records only reported to "sp." for species
nrow(filter(a, species_aw == "sp."))/nrow(a)
# Good names down to genus
sum(a$genus_aw %in% aw.genera)/nrow(a)
# Proportion of records recorded as "Non-CITES entry" for genus
nrow(filter(a, genus_aw == "Non-CITES entry"))/nrow(a)
#==============================================================================
# Generate a vector of amphibian genera restricted under the Lacey Act
lacey.act.genera <- read_csv("data/reference/Lacey_Act_species.csv") %>%
mutate(genus = str_trim(Genus, side = "both")) %>%
pull(genus) %>%
unique() %>%
sort()
# Verify all of these genera match with AmphibiaWeb taxonomy
assert_that(sum(lacey.act.genera %in% aw.genera) == length(lacey.act.genera))
# Generate a vector of amphibian species restricted under the Lacey Act
lacey.act.species <- read_csv("data/reference/Lacey_Act_species.csv") %>%
mutate(
genus = str_trim(Genus, side = "both"),
species = str_trim(Species, side = "both"),
scientific_name = paste(genus, species)
) %>%
pull(scientific_name) %>%
unique() %>%
sort()
# Four of these species do not appear in AmphibiaWeb taxonomy, but their
# generic names are captured in "lacey.act.genera" (with the exception of
# Triturus vittatus, which is reclassified as Ommatotriton vittatus)
lacey.act.species[!(lacey.act.species %in% aw.species)]
# However, Ommatotriton vittatus is documented as a Lacey Act species in the
# LEMIS dataset
lacey.act.from.lemis <- a.live %>%
filter(lacey_act == 1) %>%
pull(scientific_name) %>%
unique() %>%
sort()
lacey.act.from.lemis[!(lacey.act.from.lemis %in% lacey.act.species)]
#==============================================================================
# Generate a vector of amphibian genera known to carry Bsal
# Import the data table
bsal.summary.data <-
read_csv("data/reference/Bsal_infection_summary.csv")
nrow(bsal.summary.data)
# Which types of infection observations are present?
table(bsal.summary.data$type, useNA = "ifany")
# Verify that the species name never changed when updating from raw
# to AW taxonomy
assert_that(sum(bsal.summary.data$species == bsal.summary.data$species_aw) ==
nrow(bsal.summary.data))
# Verify that each taxa is only assigned a single Lacey Act status
bsal.summary.data %>%
group_by(genus_aw, species_aw) %>%
summarize(n_categories = n_distinct(`Lacey Act listed?`)) %>%
pull(n_categories) %>%
max()
# Which amphibian orders are represented in the Bsal carrier data?
sort(unique(bsal.summary.data$order))
# Which amphibian families are represented in the Bsal carrier data?
sort(unique(bsal.summary.data$family))
# Create a vector of Bsal carrier genera
bsal.carrier.genera <- bsal.summary.data %>%
pull(genus_aw) %>%
unique() %>%
sort()
assert_that(sum(bsal.carrier.genera %in% aw.genera) == length(bsal.carrier.genera))
length(bsal.carrier.genera)
# Create a vector of Bsal carrier species
bsal.carrier.species <- bsal.summary.data %>%
filter(species_aw != "sp.") %>%
mutate(scientific_name = paste(genus_aw, species_aw)) %>%
pull(scientific_name) %>%
unique() %>%
sort()
assert_that(sum(bsal.carrier.species %in% aw.species) == length(bsal.carrier.species))
length(bsal.carrier.species)
# Investigate which of these species was Lacey Act Listed
bsal.summary.data %>%
distinct(genus_aw, species_aw, `Lacey Act listed?`) %>%
filter(species_aw != "sp.") %>%
mutate(
scientific_name = paste(genus_aw, species_aw),
lacey_act_check = ifelse(scientific_name %in% lacey.act.species, 1, 0)
)
#==============================================================================
# In which countries has Bsal been found in the wild?
bsal.summary.data %>%
filter(type == "wild") %>%
pull(country) %>%
unique() %>%
sort()
# Generate a vector of countries of interest where Bsal has been detected in
# the wild:
# Belgium, China, Germany, Japan, Spain,
# Taiwan, Thailand, The Netherlands, Vietnam
# May also want to include Hong Kong because Bsal has been detected in
# Guangdong Province
countries.of.interest <- c("BE", "CN", "DE", "JP", "ES",
"TW", "TH", "NL", "VN", "HK")
#==============================================================================
# Bsal summary counts
# Quantify the number of imported amphibians from countries with Bsal
a.live.bsal.countries <- a.live %>%
filter(country_origin %in% countries.of.interest)
sum(a.live.bsal.countries$quantity)
a.live.bsal.countries.wild <- a.live.bsal.countries %>%
filter(source == "W")
sum(a.live.bsal.countries.wild$quantity)
# Quantify the number of imported caudates from countries with Bsal
a.live.caudates.bsal.countries <- a.live.caudates %>%
filter(country_origin %in% countries.of.interest)
sum(a.live.caudates.bsal.countries$quantity)
# Quantify the number of imported amphibians belonging to Bsal carrier genera
a.live.bsal.carrier.genera <- a.live %>%
filter(genus %in% bsal.carrier.genera)
sum(a.live.bsal.carrier.genera$quantity)
# Quantify the number of imported amphibians belonging to Bsal carrier species
a.live.bsal.carrier.species <- a.live %>%
filter(scientific_name %in% bsal.carrier.species)
sum(a.live.bsal.carrier.species$quantity)
#==============================================================================
# Summary tables
# How many unique ports of entry for live amphibians?
a.live %>%
pull(port_full) %>%
unique() %>%
sort()
# Summarize all live amphibian imports by port of entry
a.live %>%
group_by(port, port_full) %>%
summarize(
n_shipments = n(),
total_individuals = sum(quantity),
percent_individuals = total_individuals/a.live.individuals*100
) %>%
arrange(desc(total_individuals))
# Summarize all live amphibian imports by country of origin
a.live %>%
group_by(country_origin, country_origin_full) %>%
summarize(
n_shipments = n(),
total_individuals = sum(quantity),
percent_individuals = total_individuals/a.live.individuals*100
) %>%
arrange(desc(total_individuals))
# Summarize all live amphibian imports by source
a.live %>%
group_by(source) %>%
summarize(
n_shipments = n(),
total_individuals = sum(quantity),
percent_individuals = total_individuals/a.live.individuals*100
) %>%
arrange(desc(total_individuals))
# How many live individuals from various genera have been imported from 1999-
# 2021 for stated commercial purposes?
a.live %>%
filter(purpose == "T") %>%
group_by(genus_aw) %>%
summarize(quantity = sum(quantity)) %>%
ungroup() %>%
arrange(desc(quantity))
# Summarize information about reported re-exports of amphibians
a.live %>%
mutate(
matching_countries = ifelse(country_origin == country_imp_exp, 1, 0)
) %>%
group_by(matching_countries) %>%
summarize(
n_shipments = n(),
n_individuals = sum(quantity)
) %>%
ungroup() %>%
mutate(
total_shipments = sum(n_shipments),
total_individuals = sum(n_individuals),
percent_shipments = n_shipments/total_shipments,
percent_individuals = n_individuals/total_individuals
)
# Summarize live amphibian imports of Bsal carrier genera by port of entry
a.live.bsal.carrier.genera %>%
group_by(port, port_full) %>%
summarize(
n_shipments = n(),
total_individuals = sum(quantity)) %>%
arrange(desc(total_individuals))
# Summarize live amphibian imports of Bsal carrier genera by country of origin
a.live.bsal.carrier.genera %>%
group_by(country_origin, country_origin_full) %>%
summarize(
n_shipments = n(),
total_individuals = sum(quantity)) %>%
arrange(desc(total_individuals))
# Summarize live amphibian imports from Bsal endemic countries by port of entry
a.live.bsal.countries %>%
group_by(port, port_full) %>%
summarize(
n_shipments = n(),
total_individuals = sum(quantity)) %>%
arrange(desc(total_individuals))
# Summarize live amphibian imports from Bsal endemic countries by country of
# origin
a.live.bsal.countries %>%
group_by(country_origin, country_origin_full) %>%
summarize(
n_shipments = n(),
total_individuals = sum(quantity)) %>%
arrange(desc(total_individuals))
# Summarize live caudate imports from Bsal endemic countries by port of entry
a.live.caudates.bsal.countries %>%
group_by(port, port_full) %>%
summarize(
n_shipments = n(),
total_individuals = sum(quantity)) %>%
arrange(desc(total_individuals))
# Summarize live caudate imports from Bsal endemic countries by country of
# origin
a.live.caudates.bsal.countries %>%
group_by(country_origin, country_origin_full) %>%
summarize(
n_shipments = n(),
total_individuals = sum(quantity)) %>%
arrange(desc(total_individuals))
#==============================================================================
# Define palette for plotting
# https://zenodo.org/record/3381072#.Y4afhuzMJO0
Tol_bright <- c(
"#EE6677", "#228833", "#4477AA", "#CCBB44", "#66CCEE",
"#AA3377", "#BBBBBB"
)
Tol_light <- c(
"#BBCC33", "#AAAA00", "#77AADD", "#EE8866", "#EEDD88",
"#FFAABB", "#99DDFF", "#44BB99", "#DDDDDD"
)
Okabe_Ito <- c(
"#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2",
"#D55E00", "#CC79A7", "#000000"
)
palette <- c(
Okabe_Ito[-c(7)],
Tol_bright[-c(3, 5)]
)
#==============================================================================
# Question 1
# How has the live amphibian trade changed over time?
a.live %>%
group_by(shipment_year, order) %>%
summarize(quantity = sum(quantity)) %>%
ungroup() %>%
mutate(order = ifelse(is.na(order), "Unknown", order)) %>%
ggplot(aes(x = shipment_year + 0.5, y = quantity,
fill = order)) +
geom_col() +
labs(x = "Shipment Year", y = "Number of Individuals", fill = "Order") +
theme_minimal() +
scale_y_continuous(labels = scales::comma) +
scale_fill_manual(values = palette) +
theme(
plot.title = element_text(face = "bold"),
text = element_text(size = 20),
axis.title.x = element_text(face = "bold", size = 22),
axis.title.y = element_text(face = "bold", size = 22),
panel.grid.minor.x = element_blank(),
legend.title = element_blank(),
legend.text = element_text(size = 22),
legend.position = c(0.8, 0.85),
legend.background = element_rect(),
legend.spacing.y = unit(1, "mm"),
plot.background = element_rect(color = "white")
)
ggsave("outputs/Fig1.png", width = 10, height = 8)
a.live.table <- a.live %>%
group_by(shipment_year) %>%
summarize(quantity = sum(quantity)) %>%
ungroup() %>%
mutate(
shipment_year_s = shipment_year - 2016,
before_after = ifelse(shipment_year >= 2016, 1, 0)
)
# What's the average number of live amphibians imported per year?
mean(a.live.table$quantity)
# What's the trend over time?
# Fit model
out <- glm(
quantity ~ shipment_year_s,
data = a.live.table,
family = poisson
)
# Summarize model
summary(out)
fitted <- fitted.values(out)
diffs <- sapply(2:length(fitted), function(x) fitted[x] - fitted[x-1])
mean(diffs)
# Visualize model
plot(quantity ~ shipment_year, data = a.live.table, ylim = c(0, 1e7))
lines(a.live.table$shipment_year, fitted)
# What's the average number of live amphibians imported per year since 2016?
a.live.table %>%
filter(shipment_year >= 2016) %>%
pull(quantity) %>%
mean()
# Table giving percentages for the plot above
a.live %>%
group_by(shipment_year, order) %>%
summarize(quantity = sum(quantity)) %>%
ungroup() %>%
left_join(., a.live.table, by = "shipment_year") %>%
mutate(yearly_percent = quantity.x/quantity.y*100)
a.leg.meat.table <- a.leg.meat %>%
group_by(shipment_year) %>%
summarize(quantity = sum(quantity)) %>%
ungroup()
# What's the average kg of amphibian legs/meat imported per year?
mean(a.leg.meat.table$quantity)
# Break the leg and meat trade down by species
a.leg.meat %>%
group_by(genus_aw, species_aw) %>%
summarize(quantity = sum(quantity)) %>%
ungroup() %>%
arrange(desc(quantity)) %>%
mutate(
tot_quantity = sum(a.leg.meat$quantity),
percent = quantity/tot_quantity
)
#==============================================================================
# Question 2
# What percentage of live amphibians imported to the US are coming from
# countries with Bsal and how has this changed over time?
key.bsal.countries <- c("CN", "HK", "TW")
a.live %>%
mutate(
country_origin_mod = case_when(
country_origin %in% key.bsal.countries ~ country_origin_full,
country_origin %in% countries.of.interest ~ "Other Bsal Country",
TRUE ~ "Non-Bsal Country"
),
country_origin_mod = as.factor(country_origin_mod),
country_origin_mod = forcats::fct_relevel(country_origin_mod,
"China", "Hong Kong", "Taiwan", "Other Bsal Country", "Non-Bsal Country")
) %>%
group_by(shipment_year, country_origin_mod) %>%
summarize(quantity = sum(quantity)) %>%
ungroup() %>%
ggplot(aes(x = shipment_year + 0.5, y = quantity,
fill = country_origin_mod)) +
geom_col() +
labs(x = "Shipment Year", y = "Number of Individuals", fill = "Country") +
theme_minimal() +
scale_y_continuous(labels = scales::comma) +
scale_fill_manual(
values = palette,
breaks = c("China", "Hong Kong", "Taiwan",
"Other Bsal Country", "Non-Bsal Country"),
labels = c("China", "Hong Kong", "Taiwan",
"Other *Bsal* Country", "Non-*Bsal* Country"),
) +
theme(
plot.title = element_text(face = "bold"),
text = element_text(size = 20),
axis.title.x = element_text(face = "bold", size = 22),
axis.title.y = element_text(face = "bold", size = 22),
panel.grid.minor.x = element_blank(),
legend.title = element_blank(),
legend.text = element_markdown(size = 22),
legend.position = c(0.75, 0.85),
legend.background = element_rect(),
legend.spacing.y = unit(1, "mm"),
plot.background = element_rect(color = "white")
)
ggsave("outputs/Fig2.png", width = 10, height = 8)
# Table giving percentages for the plot above
a.live %>%
mutate(
country_origin_mod = case_when(
country_origin %in% countries.of.interest ~ country_origin_full,
TRUE ~ "Non-Bsal Country"
)
) %>%
group_by(shipment_year, country_origin_mod) %>%
summarize(quantity = sum(quantity)) %>%
ungroup() %>%
left_join(., a.live.table, by = "shipment_year") %>%
mutate(yearly_percent = quantity.x/quantity.y*100)
a.live %>%
mutate(
country_origin_mod = case_when(
country_origin %in% countries.of.interest ~ "Bsal Country",
TRUE ~ "Non-Bsal Country"
)
) %>%
group_by(shipment_year, country_origin_mod) %>%
summarize(quantity = sum(quantity)) %>%
ungroup() %>%
left_join(., a.live.table, by = "shipment_year") %>%
mutate(yearly_percent = quantity.x/quantity.y*100)
# Compare with exporting countries for wildlife trade more generally
l <- lemis::lemis_data() %>%
filter(description == "LIV") %>%
collect()
total.live.individuals <- sum(l$quantity)
l %>%
group_by(country_origin) %>%
summarize(quantity = sum(quantity)) %>%
ungroup() %>%
mutate(percent = quantity/total.live.individuals*100) %>%
arrange(desc(quantity))
# Plot with only Bsal countries
a.live %>%
filter(country_origin %in% countries.of.interest) %>%
group_by(shipment_year, country_origin_full) %>%
summarize(quantity = sum(quantity)) %>%
ungroup() %>%
ggplot(aes(x = shipment_year + 0.5, y = quantity,
fill = country_origin_full)) +
geom_col() +
labs(x = "Shipment Year", y = "Number of Individuals", fill = "Country") +
theme_minimal() +
scale_y_continuous(labels = scales::comma) +
scale_fill_manual(values = palette) +
theme(
plot.title = element_text(face = "bold"),
text = element_text(size = 20),
axis.title.x = element_text(face = "bold", size = 22),
axis.title.y = element_text(face = "bold", size = 22),
legend.title = element_blank(),
plot.background = element_rect(color = "white")
)
ggsave("outputs/live_amphibian_imports_by_country_only_Bsal_positive.png",
width = 10, height = 8)
#==============================================================================
# Question 3
# Ports
ports.of.interest <- c("LA", "NY", "SF", "BV", "MI")
a.live %>%
mutate(
port_full_mod = case_when(
port %in% ports.of.interest ~ port_full,
TRUE ~ "Other"
),
port_full_mod = as.factor(port_full_mod),
port_full_mod = forcats::fct_relevel(port_full_mod,
"Other", after = Inf)
) %>%
group_by(shipment_year, port_full_mod) %>%
summarize(quantity = sum(quantity)) %>%
ungroup() %>%
ggplot(aes(x = shipment_year + 0.5, y = quantity,
fill = port_full_mod)) +
geom_col() +
labs(x = "Shipment Year", y = "Number of Individuals", fill = "Port") +
theme_minimal() +
scale_y_continuous(labels = scales::comma) +
scale_fill_manual(values = palette) +
theme(
plot.title = element_text(face = "bold"),
text = element_text(size = 20),
axis.title.x = element_text(face = "bold", size = 22),
axis.title.y = element_text(face = "bold", size = 22),
panel.grid.minor.x = element_blank(),
legend.title = element_blank(),
legend.text = element_text(size = 22),
legend.position = c(0.8, 0.85),
legend.background = element_rect(),
legend.spacing.y = unit(1, "mm"),
plot.background = element_rect(color = "white")
)
ggsave("outputs/Fig3.png", width = 10, height = 8)
# Table giving percentages for the plot above
a.live %>%
mutate(
port_full_mod = case_when(
port %in% ports.of.interest ~ port_full,
TRUE ~ "Other"
)
) %>%
group_by(shipment_year, port_full_mod) %>%
summarize(quantity = sum(quantity)) %>%
ungroup() %>%
left_join(., a.live.table, by = "shipment_year") %>%
mutate(yearly_percent = quantity.x/quantity.y*100)
# Compare with ports of entry for wildlife trade more generally
l %>%
group_by(port) %>%
summarize(quantity = sum(quantity)) %>%
ungroup() %>%
mutate(percent = quantity/total.live.individuals*100) %>%
arrange(desc(quantity))
#==============================================================================
# Question 4
# How has the Lacey Act affected amphibian trade?
key.lacey.act.genera <- c(
"Cynops", "Paramesotriton", "Pleurodeles",
"Salamandra", "Triturus", "Other Lacey Act Genera"
)
panel.a <- a.live %>%
filter(genus_aw %in% lacey.act.genera) %>%
mutate(
genus_aw = ifelse(
genus_aw %in% key.lacey.act.genera,
genus_aw,
"Other Lacey Act Genera"
),
genus_aw = as.factor(genus_aw),
genus_aw = forcats::fct_relevel(genus_aw, key.lacey.act.genera)
) %>%
group_by(shipment_year, genus_aw) %>%
summarize(quantity = sum(quantity)) %>%
ungroup() %>%
ggplot(aes(x = shipment_year + 0.5, y = quantity,
fill = genus_aw)) +
geom_col() +
labs(x = "Shipment Year", y = "Number of Individuals", fill = "Genus") +
theme_minimal() +
scale_y_continuous(labels = scales::comma) +
scale_fill_manual(
values = palette,
breaks = c("Cynops", "Paramesotriton", "Pleurodeles",
"Salamandra", "Triturus", "Other Lacey Act Genera"),
labels = c("*Cynops*", "*Paramesotriton*", "*Pleurodeles*",
"*Salamandra*", "*Triturus*", "Other Lacey Act Genera")
) +
theme(
plot.title = element_text(face = "bold"),
text = element_text(size = 20),
axis.title.x = element_text(face = "bold", size = 22),
axis.title.y = element_text(face = "bold", size = 22),
panel.grid.minor.x = element_blank(),
legend.title = element_blank(),
legend.text = element_markdown(size = 22),
legend.position = c(0.75, 0.8),
legend.background = element_rect(),
legend.spacing.y = unit(1, "mm"),
plot.background = element_rect(color = "white")
)
panel.b <- a.live %>%
filter(genus_aw %in% lacey.act.genera) %>%
filter(shipment_year >= 2016) %>%
mutate(
genus_aw = ifelse(
genus_aw %in% key.lacey.act.genera,
genus_aw,
"Other Lacey Act Genera"
),
genus_aw = as.factor(genus_aw),
genus_aw = forcats::fct_relevel(genus_aw, key.lacey.act.genera)
) %>%
group_by(shipment_year, genus_aw) %>%
summarize(quantity = sum(quantity)) %>%
ungroup() %>%
ggplot(aes(x = shipment_year + 0.5, y = quantity,
fill = genus_aw)) +
geom_col() +
labs(x = "Shipment Year", y = "Number of Individuals", fill = "Genus") +
theme_minimal() +
scale_x_continuous(breaks = 2016:2022) +
scale_y_continuous(labels = scales::comma, n.breaks = 6) +
scale_fill_manual(values = palette) +
theme(
plot.title = element_text(face = "bold"),
text = element_text(size = 16),
axis.title.x = element_text(face = "bold", size = 18),
axis.title.y = element_text(face = "bold", size = 18),
panel.grid.minor.x = element_blank(),
legend.title = element_blank(),
legend.position = "none",
plot.background = element_rect(color = "white")
)
panel.b <- cowplot::plot_grid(
NULL, panel.b, NULL,
nrow = 1, rel_widths = c(2, 6, 2),
labels = c("", "b", ""), label_size = 20)
cowplot::plot_grid(
panel.a, panel.b,
labels = c("a", ""), label_size = 20,
ncol = 1, rel_heights = c(6, 4)
)
ggsave("outputs/Fig4.png", width = 10, height = 10)
a.live.lacey.table <- a.live %>%
filter(genus_aw %in% lacey.act.genera) %>%
group_by(shipment_year) %>%
summarize(quantity = sum(quantity)) %>%
ungroup()
nrow(a.live.lacey.table)
# No Lacey Act genera in 2018 at all, so add that data
a.live.lacey.table <- bind_rows(
a.live.lacey.table,
data.frame(shipment_year = 2018, quantity = 0)
) %>%
arrange(shipment_year) %>%
mutate(
shipment_year_s = shipment_year - 2016,
before_after = ifelse(shipment_year >= 2016, 1, 0)
)
nrow(a.live.lacey.table)
# What's the average number of live amphibians imported per year?
mean(a.live.lacey.table$quantity)
# What's the trend over time?
# Fit model
out <- glm(
quantity ~ shipment_year_s,
data = a.live.lacey.table,
family = poisson
)
# Summarize model
summary(out)
fitted <- fitted.values(out)
diffs <- sapply(2:length(fitted), function(x) fitted[x] - fitted[x-1])
mean(diffs)
# Visualize model
plot(quantity ~ shipment_year, data = a.live.lacey.table, ylim = c(0, 1e6))
lines(a.live.table$shipment_year, fitted)
# Impact evaluation analysis
# Model-fitting for the intervention group (Lacey Act listed species)
out.i <- glm(
quantity ~ shipment_year_s * before_after,
data = a.live.lacey.table,
family = poisson
)
summary(out.i)
fitted.i <- fitted.values(out.i)
# Create panel for plot
fitted.df.i <- data.frame(
shipment_year = a.live.lacey.table$shipment_year,
pred = fitted.i
)
panel.a <- a.live.lacey.table %>%
ggplot(aes(x = shipment_year + 0.5, y = quantity)) +
geom_col(fill = alpha("black", 0.4)) +
geom_line(
aes(x = shipment_year + 0.5, y = pred),
col = "black", size = 1.5,
data = fitted.df.i[1:17,]
) +
geom_line(
aes(x = shipment_year + 0.5, y = pred),
col = "black", size = 1.5,
data = fitted.df.i[18:23,]
) +
geom_vline(xintercept = 2016, size = 1, lty = 2) +
labs(x = "", y = "Number of Individuals") +
xlim(1999, 2022) +
theme_minimal() +
scale_y_continuous(
labels = scales::comma,
limits = c(0, 1e6)
) +
theme(
plot.title = element_text(face = "bold"),
text = element_text(size = 20),
axis.title.x = element_text(face = "bold", size = 22),
axis.title.y = element_text(face = "bold", size = 22),
panel.grid.minor.x = element_blank(),
plot.background = element_rect(color = "white")
)
# Repeat the same analysis for the control group (non-listed species)
a.live.non.lacey.table <- a.live %>%
filter(!(genus_aw %in% lacey.act.genera)) %>%
group_by(shipment_year) %>%
summarize(quantity = sum(quantity)) %>%
ungroup() %>%
mutate(
shipment_year_s = shipment_year - 2016,
before_after = ifelse(shipment_year >= 2016, 1, 0)
)
nrow(a.live.non.lacey.table)
# Verify that "a.live.non.lacey.act.table" represents all live trade
# not represented by "a.live.lacey.act.table"
sum(a.live.lacey.table$quantity) + sum(a.live.non.lacey.table$quantity) ==
sum(a.live$quantity)
# What's the average number of live amphibians imported per year?
mean(a.live.non.lacey.table$quantity)
# Model-fitting
out.c <- glm(
quantity ~ shipment_year_s * before_after,
data = a.live.non.lacey.table,
family = poisson
)
summary(out.c)
fitted.c <- fitted.values(out.c)
# Create a panel for plot
fitted.df.c <- data.frame(
shipment_year = a.live.non.lacey.table$shipment_year,
pred = fitted.c
)
panel.b <- a.live.non.lacey.table %>%
ggplot(aes(x = shipment_year + 0.5, y = quantity)) +
geom_col(fill = alpha("forestgreen", 0.4)) +
geom_line(
aes(x = shipment_year + 0.5, y = pred),
col = "forestgreen", size = 1.5,
data = fitted.df.c[1:17,]
) +
geom_line(
aes(x = shipment_year + 0.5, y = pred),
col = "forestgreen", size = 1.5,
data = fitted.df.c[18:23,]
) +
geom_vline(xintercept = 2016, size = 1, lty = 2) +
labs(x = "Shipment Year", y = "Number of Individuals") +
xlim(1999, 2022) +
theme_minimal() +
scale_y_continuous(
labels = scales::comma,
limits = c(0, 6e6)
) +
theme(
plot.title = element_text(face = "bold"),
text = element_text(size = 20),