-
Notifications
You must be signed in to change notification settings - Fork 0
/
04_Philippines.R
633 lines (524 loc) · 27.2 KB
/
04_Philippines.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
#' ---
#' title: "Philippines Analysis Script"
#' author: "MS Patterson, [email protected]"
#' date: "`r format(Sys.time(), '%B %d, %Y')`"
#' output: [github_document, word_document]
#' ---
#'
#'
#' Set working directory to where data is being stored.
#+ setwd
#setwd("~/R/GIA/")
#' ### Required packages
#+ Packages
library(tidyverse)
library(knitr)
library(rmarkdown)
source("00_GIA_functions.R")
#+ user_supplied_variables
# User needs to supply variables -----------------------------------------------
# Area of strata and sample sizes
country <- "Philippines"
strata <- c(1, 2, 3)
stratumAreas <- c("Strata1 Area" = 166007, "Strata2 Area" = 686867,
"Strata3 Area" = 29147220)
# Metadata to save, and Grouping Variables
metaNames <- c("PLOT_ID", "SAMPLE_ID", "USER_ID", "PL_PLOTID", "PL_PACKETID",
"PL_COUNTRY", "PL_STRATUM")
groupList <- c("PL_COUNTRY", "PL_STRATUM", "PLOT_ID")
# Survey Questions
questions <- c("LAND_COVER", "UNDERSTORY_PRESENT", "UNDERSTORY_COVER",
"LAND_USE", "LAND_USE_YEAR_2000", "TCC")
covOrder <- c("Aquaculture", "Banana" ,"Bamboo","Coconut","Coffee","Fruit_Nut",
"Oil_Palm", "Pulpwood", "Rubber", "Rice", "Tea", "Other_Crop",
"Other_Palm", "Other_Tree", "Other_Shrub", "Herbaceous",
"Non_vegetated", "Built_up", "Water", "Other_LAND_COVER")
#no terrace in Cambodia, so removed here.
useOrder <- c("Agrisiviculture", "Boundary_Agrisilviculture",
"Mixed_Agrisilviculture", "Silvopastoral", "Plantation",
"Terrace", "Natural_Forest", "Other_LAND_USE")
#+ inputdata
# Data input and cleaning ------------------------------------------------------
rawData <- read_csv("data/Corrected/Philippines.csv",
col_types = "ddddldcdcdddcdccccc")
# Add a tree canopy cover variable
rawData <- rawData %>%
mutate(TCC = case_when(
LAND_USE_YEAR_2000 == "Forest_Commodity" ~ "Tree",
LAND_USE_YEAR_2000 == "Natural_Forest" ~ "Tree",
LAND_USE_YEAR_2000 == "Other_LAND_USE_YEAR_2000" ~ "Not_Tree"
)
)
# remove unneeded columns
keep <- c(metaNames, "FLAGGED", questions)
rawData <- rawData[,keep]
#Determine actual sample size
sampSize <- c(length(unique(rawData[which(rawData$PL_STRATUM == 1),]$PL_PLOTID)),
length(unique(rawData[which(rawData$PL_STRATUM == 2),]$PL_PLOTID)),
length(rawData[which(rawData$PL_STRATUM == 3),]$PL_PLOTID)/24)
paste("There are", sampSize[1], "samples in stratum 1,", sampSize[2],
"samples in stratum 2, and", sampSize[3], "samples in stratum 3")
#+ Analysis
# Analysis ---------------------------------------------------------------------
generalResults <- do_yc_analysis(table = rawData, mtdt = metaNames, strata = strata,
ns = sampSize, areas = stratumAreas, qstns = questions,
grplst = groupList)
# calculate top level areas
coverArea <- t(generalResults$Cover$LAND_COVER) * sum(stratumAreas)
colnames(coverArea) <- c("Area_ha", "SE_Area_ha")
useArea <- t(generalResults$Cover$LAND_USE) * sum(stratumAreas)
colnames(useArea) <- c("Area_ha", "SE_Area_ha")
use2000Area <- t(generalResults$Cover$LAND_USE_YEAR_2000) * sum(stratumAreas)
colnames(use2000Area) <- c("Area_ha", "SE_Area_ha")
tcc2000Area <- t(generalResults$Cover$TCC) * sum(stratumAreas)
colnames(tcc2000Area) <- c("Area (ha)", "SE Area (ha)")
# top level area tables
coverAreaPretty <- as_tibble(coverArea, rownames = "cover")
colnames(coverAreaPretty) <- c("cover", "Area (ha)", "SE Area (ha)")
coverAreaPretty <- arrange(coverAreaPretty, match(cover, covOrder))
captionQ1 <- paste("Table R1. The estimated area in each land cover type for",
country, "in the period after 2015. This data was collected",
"using question 1 in the Collect Earth Online survey,",
"based on Digital Globe and Bing imagery.")
kable(coverAreaPretty, digits = 0, caption = captionQ1)
useAreaPretty <- as_tibble(useArea,rownames = "use")
colnames(useAreaPretty) <- c("use", "Area (ha)", "SE Area (ha)")
useAreaPretty <- arrange(useAreaPretty, match(use, useOrder))
captionQ2 <- paste("Table R2. The estimated area in each land use type for",
country, "in the period after 2015. This data was collected",
"using question 2 in the Collect Earth Online survey,",
"based on Digital Globe and Bing imagery.")
kable(useAreaPretty, digits = 0, caption = captionQ2)
captionQ3 <- paste("Table R3. The estimated area in each land use type for",
country, "in the year 2000. This data was collected",
"using question 3 in the Collect Earth Online survey,",
"based on Landsat time series imagery.")
kable(use2000Area, digits = 0, caption = captionQ3)
captionQ4 <- paste("Table R4. The estimated area of tree canopy cover in",
country, "for the year 2000. This data was collected using",
"question 3 in the Collect Earth Online survey,",
"based on Landsat time series imagery.")
kable(tcc2000Area, digits = 0, caption = captionQ4)
#+ y_oc
# Object in cover analyses -----------------------------------------------------
coverIn2000 <- do_yoc_analysis(rawData, mtdt = metaNames, qstns = questions2,
grplst = groupList, strata = strata, ns = sampSize,
areas = stratumAreas, cvrfld = "LAND_COVER",
cndtnfld = "LAND_USE_YEAR_2000")
coverInUse <- do_yoc_analysis(rawData, mtdt = metaNames, qstns = questions2,
grplst = groupList, strata = strata, ns = sampSize,
areas = stratumAreas, cvrfld = "LAND_COVER",
cndtnfld = "LAND_USE")
useinCover <- do_yoc_analysis(rawData, mtdt = metaNames, qstns = questions2,
grplst = groupList, strata = strata, ns = sampSize,
areas = stratumAreas, cvrfld = "LAND_USE",
cndtnfld = "LAND_COVER")
useinUse2000 <- do_yoc_analysis(rawData, mtdt = metaNames, qstns = questions2,
grplst = groupList, strata = strata, ns = sampSize,
areas = stratumAreas, cvrfld = "LAND_USE",
cndtnfld = "LAND_USE_YEAR_2000")
# calculate class interaction areas
coverIn2000Area <- calcError(coverIn2000, use2000Area, 3, 4, 1, 2)
coverInUseArea <- calcError(coverInUse, useArea, 3, 4, 1, 2)
useInCoverArea <- calcError(useinCover, coverArea, 3, 4, 1, 2)
useInUse2000Area <- calcError(useinUse2000, use2000Area, 3, 4, 1, 2)
#+ prettyTables
## produce tidy output tables for "object in cover" ----------------------------
# area of covers in recent uses
coverInUseArea %>%
mutate(Pretty = paste(round(Value), round(Error), sep = " \u00B1 ")) %>%
select(Cover, Condition, Pretty) %>%
spread(Condition, Pretty) %>%
arrange(match(Cover, covOrder)) %>%
select(Cover, useOrder) %>%
kable(., align = "lrrr",
caption = c("Table R5. Estimate of area and standard error of the area
of each land cover (in hectares), that occurred in each of
the land uses that were labeled for the period after 2015.
All the agrisilvicultural land uses have been summed for
readability. ‘Other Crop’ contains any agricultural or
crop land covers that could not be identified during the
photo interpretation process. ‘Other Land Cover’ contains
all other land covers that did not fit into the other
categories in strata 1 & 2, and all land covers in plots
in stratum 3 that did not experience forest loss or gain."))
# area of covers in 2000 uses
coverIn2000Area %>%
mutate(Pretty = paste(round(Value), round(Error), sep = " \u00B1 ")) %>%
select(Cover, Condition, Pretty) %>%
spread(Condition, Pretty) %>%
arrange(match(Cover, covOrder)) %>%
kable(., align = "lrrr",
caption = c("Table R6. Estimate of area and standard error of the area of each
land cover (in hectares), that occurred in each of the land uses
that were labelled in the year 2000. ‘Other Crops’ contains any
agricultural or crop land covers that could not be identified
during the photo interpretation process. ‘Other Land Cover’
contains all other land covers that did not fit into the other
categories in strata 1 & 2, and all land covers in plots in
stratum 3 that did not experience forest loss or gain."))
# area of recent uses in covers
useInCoverArea %>%
mutate(Pretty = paste(round(Value), round(Error), sep = " \u00B1 ")) %>%
select(Cover, Condition, Pretty) %>%
spread(Cover, Pretty) %>%
arrange(match(Condition, useOrder)) %>%
select(Condition, useOrder) %>%
kable(., align = "lrrr",
caption = c("Table R7. Estimate of area and standard error of the area of each
land cover (in hectares), that occurred in each of the land uses
that were labelled in the year 2015. ‘Other Crops’ contains any
agricultural or crop land covers that could not be identified
during the photo interpretation process. ‘Other Land Cover’
contains all other land covers that did not fit into the other
categories in strata 1 & 2, and all land covers in plots in
stratum 3 that did not experience forest loss or gain."))
# area of recent uses in 2000 uses
useInUse2000Area %>%
mutate(Pretty = paste(round(Value), round(Error), sep = " \u00B1 ")) %>%
select(Cover, Condition, Pretty) %>%
spread(Condition, Pretty) %>%
arrange(match(Cover, useOrder)) %>%
kable(., align = "lrrr",
caption = c("Table R8. Estimate area and standard error (in hectares) of
each land use from the period after 2015 occuring in each land
use type in 2000. ‘Other Land Use’ contains all other land
covers that did not fit into the other categories"))
#+ y_occ1
# Former Forest only -----------------------------------------------------------
#' Triple conditional for area of commodities that were forested in the year
#' 2000.
questions2 <- c("LAND_COVER", "LAND_USE", "LAND_USE_YEAR_2000")
crops <- c("Banana", "Coconut", "Coffee", "Fruit_Nut" ,"Pulpwood", "Rice",
"Rubber", "Oil_Palm", "Tea", "Other_Crop", "Other_Tree", "Other_Palm",
"Other_Shrub", "Herbaceous", "Other_LAND_COVER")
y_occ <- build_yocc(rawData, mtdt = metaNames, qstns = questions2,
cvrfld = "LAND_COVER", cndtnfld1 = "LAND_USE",
cndtnfld2 = "LAND_USE_YEAR_2000", covers = crops,
conditions1 = NULL, conditions2 = "Natural_Forest")
y_occResults <- do_yocc_analysis(y_occ, mtdt = metaNames, strata = strata,
areas = stratumAreas, ns = sampSize,
qstns = questions2, grplst = groupList)
# calculate areas, make table
cResults <- bind_rows(y_occResults$Cover)
cTableP1 <- cResults %>%
mutate(PercentCover = PercentCover * sum(stratumAreas),
SE = SE * sum(stratumAreas)) %>%
mutate(Pretty = paste(round(PercentCover), round(SE), sep = " \u00B1 ")) %>%
select(cover, condition1, Pretty) %>%
spread(condition1, Pretty) %>%
arrange(match(cover, covOrder)) %>%
select(cover, useOrder)
kable(cTableP1, digits = 0, col.names = c("Crops", useOrder), align = "lrrr",
caption = c("Table R9. Estimate of area and standard error of each
commodity land cover (in hectares), by land use, in areas that were
forested in the year 2000 and experienced forest cover loss between
2001 and 2015. ‘Other Crops’ contains any agricultural or crop land
covers that could not be identified during the photo interpretation
process. ‘Other Land Use’ contains all other land covers that did not fit
into the other categories."))
#+ y_occ2
# Support FF in 2000 ----------------------------------------------------------
#' Triple conditional for "support area" of commodities that were had forest cover
#' in the year 2000.
support <- c("Built_up", "Non_vegetated", "Other_LAND_COVER", "Water")
y_occ2 <- build_yocc(rawData, mtdt = metaNames, qstns = questions,
cvrfld = "LAND_COVER", cndtnfld1 = "LAND_USE",
cndtnfld2 = "TCC", covers = support,
conditions1 = NULL, conditions2 = "Tree")
y_occResults2 <- do_yocc_analysis(y_occ2, mtdt = metaNames, strata = strata,
areas = stratumAreas, ns = sampSize,
qstns = questions2, grplst = groupList)
# calculate areas
cResults2 <- bind_rows(y_occResults2$Cover)
cTableP2 <- cResults2 %>%
mutate(PercentCover = PercentCover * sum(stratumAreas),
SE = SE * sum(stratumAreas)) %>%
mutate(Pretty = paste(round(PercentCover), round(SE), sep = " \u00B1 ")) %>%
select(cover, condition1, Pretty) %>%
spread(condition1, Pretty) %>%
arrange(match(cover, covOrder)) %>%
select(cover, useOrder)
kable(cTableP2, digits = 0, col.names = c("Crops", useOrder), align = "lrrr",
caption = c("Table R11. Estimate of area and standard error of each
commodity \'support\' land cover (in hectares), by land use, in areas that
had tree cover in the year 2000 and experienced tree canopy loss between
2001 and 2015. ‘Other Crops’ contains any agricultural or crop land
covers that could not be identified during the photo interpretation
process. ‘Other Land Use’ contains all other land covers that did not fit
into the other categories."))
#+ y_occ3
# Crops in TCC in 2000 ---------------------------------------------------------
#' Triple conditional for area of commodities that were had tree cover in the
#' year 2000.
questions3 <- c("LAND_COVER", "LAND_USE", "TCC")
crops <- c("Banana", "Coconut", "Coffee", "Fruit_Nut" ,"Pulpwood", "Rice",
"Rubber", "Oil_Palm", "Tea", "Other_Crop", "Other_Tree", "Other_Palm",
"Other_Shrub", "Herbaceous")
y_occ3 <- build_yocc(rawData, mtdt = metaNames, qstns = questions3,
cvrfld = "LAND_COVER", cndtnfld1 = "LAND_USE",
cndtnfld2 = "TCC", covers = crops,
conditions1 = NULL, conditions2 = "Tree")
y_occResults3 <- do_yocc_analysis(y_occ3, mtdt = metaNames, strata = strata,
areas = stratumAreas, ns = sampSize,
qstns = questions3, grplst = groupList)
# calculate areas
cResults3 <- bind_rows(y_occResults3$Cover)
cTableP3 <- cResults3 %>%
mutate(PercentCover = PercentCover * sum(stratumAreas),
SE = SE * sum(stratumAreas)) %>%
mutate(Pretty = paste(round(PercentCover), round(SE), sep = " \u00B1 ")) %>%
select(cover, condition1, Pretty) %>%
spread(condition1, Pretty) %>%
arrange(match(cover, covOrder)) %>%
select(cover, useOrder)
kable(cTableP3, digits = 0, col.names = c("Crops", useOrder), align = "lrrr",
caption = c("Table R10. Estimate of area and standard error of each
commodity land cover (in hectares), by land use, in areas that had tree
cover in the year 2000 and experienced tree canopy cover loss between
2001 and 2015. ‘Other Crops’ contains any agricultural or crop land
covers that could not be identified during the photo interpretation
process. ‘Other Land Use’ contains all other land covers that did not fit
into the other categories."))
#+ y_occ4
# Support TCC in 2000 ----------------------------------------------------------
#' Triple conditional for "support area" of commodities that were had tree cover
#' in the year 2000.
support <- c("Built_up", "Non_vegetated", "Other_LAND_COVER", "Water")
y_occ4 <- build_yocc(rawData, mtdt = metaNames, qstns = questions3,
cvrfld = "LAND_COVER", cndtnfld1 = "LAND_USE",
cndtnfld2 = "TCC", covers = support,
conditions1 = NULL, conditions2 = "Tree")
y_occResults4 <- do_yocc_analysis(y_occ4, mtdt = metaNames, strata = strata,
areas = stratumAreas, ns = sampSize,
qstns = questions3, grplst = groupList)
# calculate areas
cResults4 <- bind_rows(y_occResults4$Cover)
cTableP4 <- cResults4 %>%
mutate(PercentCover = PercentCover * sum(stratumAreas),
SE = SE * sum(stratumAreas)) %>%
mutate(Pretty = paste(round(PercentCover), round(SE), sep = " \u00B1 ")) %>%
select(cover, condition1, Pretty) %>%
spread(condition1, Pretty) %>%
arrange(match(cover, covOrder)) %>%
select(cover, useOrder)
kable(cTableP4, digits = 0, col.names = c("Crops", useOrder), align = "lrrr",
caption = c("Table R11. Estimate of area and standard error of each
commodity \'support\' land cover (in hectares), by land use, in areas that
had tree cover in the year 2000 and experienced tree canopy loss between
2001 and 2015. ‘Other Crops’ contains any agricultural or crop land
covers that could not be identified during the photo interpretation
process. ‘Other Land Use’ contains all other land covers that did not fit
into the other categories."))
#' ## Understory analysis
#' Investigate presence of understory
# Understory -------------------------------------------------------------------
sum(rawData$UNDERSTORY_PRESENT == "Yes")
unique(rawData$UNDERSTORY_COVER)
#' 111 points in other crops and coffee exist as understory.
#' Will exclude, from carbon numbers, as it's already included in the
#' agroforestry landuse by default. But maybe should mention the area.
underCrops <- c("Coffee", "Other_Crop")
treeCrops <- c("Coconut", "Fruit_Nut" ,"Pulpwood", "Rubber", "Oil_Palm",
"Other_Tree", "Other_Palm", "Other_Crop")
uy_occ <- build_yocc(rawData, mtdt = metaNames, qstns = questions,
cvrfld = "UNDERSTORY_COVER", cndtnfld1 = "LAND_COVER",
cndtnfld2 = "UNDERSTORY_PRESENT", covers = underCrops,
conditions1 = treeCrops, conditions2 = "Yes")
uy_occResults <- do_yocc_analysis(uy_occ, mtdt = metaNames, strata = strata,
areas = stratumAreas, ns = sampSize,
qstns = questions, grplst = groupList)
uResults <- bind_rows(uy_occResults$Cover)
colnames(uResults) <- c("understory", "overstory", "present", "PercentCover", "SE")
uResults %>%
mutate(PercentCover = PercentCover * sum(stratumAreas),
SE = SE * sum(stratumAreas)) %>%
mutate(Pretty = paste(round(PercentCover), round(SE), sep = " \u00B1 ")) %>%
select(understory, overstory, Pretty) %>%
spread(understory, Pretty)
#' ## Carbon Analysis
#+ Carbon
# calculate Carbon values for areas --------------------------------------------
carbonMono <- c("Banana" = 5.7, #from Philippines
"Coconut" = 24.1, #From Philippines
"Coffee" = 5.4, # From Vietnam
"Fruit_Nut" = 43.81, # mean of rambutan, mango, santol
"Pulpwood" = 23, # from Vietnam
"Rubber" = 107.3, # mean of time averaged
"Oil_Palm" = 38.97, # from Indonesia
"Rice" = 3.1, # From Philippines
"Tea" = 15.53, # from Vietnam
"Other_Crop" = 5.14, # Various crops in Philippines
"Other_Tree" = 49.55, # mean of trees
"Other_Palm" = 22.92, # average of palms
"Other_Shrub" = 10.46, # mean of shrubs
"Herbaceous" = 6.52) # Philippines grasslands
carbonAF <- c("Banana" = 5.7, #from Philippines
"Coffee" = 30.8, # From Vietnam
"Coconut" = 41.3, #From Philippines
"Fruit_Nut" = 44.33, # mean of rambutan, mango, santol
"Pulpwood" = 23, # from Vietnam
"Rubber" = 107.3, # mean of time averaged
"Oil_Palm" = 38.97, # from Indonesia
"Rice" = 3.1, # From Philippines
"Tea" = 22, # from Vietnam
"Other_Crop" = 20, # from Vietnam
"Other_Tree" = 49.68, #mean of trees
"Other_Palm" = 28.66, # average of palms
"Other_Shrub" = 16.5, #mean of shrubs
"Herbaceous" = 20) # same as "other crops"
kable(cbind(carbonMono, carbonAF), digits = 1,
col.names = c("Monoculture", "Agroforestry"),
caption = c("Table R12. Carbon factors used to calculate the aboveground
biomass for each commodity. Values for commodities were compiled for
monoculture and agroforestry systems from peer-reviewed and grey
literature. Time-averaged values are often used to estimate the carbon
storage of rotational commodity crops because they allow for the
“averaging” of a mixture of freshly replanted and mature commodity areas
across the landscape. Sources for the carbon values presented here are
included in Appendix 1."))
# calculate Carbon values for previously forested areas ------------------------
# make results into an area
ffAreas <- arrange(cResults, cover) %>%
mutate(PercentCover = PercentCover * sum(stratumAreas),
SE = SE * sum(stratumAreas))
colnames(ffAreas) <-c("cover", "condition1", "condition2", "area", "SE")
### agroforestry carbon
ffA <- filter(ffAreas, condition1 == "Agrisiviculture") #keep all elements
ffBA <- filter(ffAreas, condition1 == "Boundary_Agrisilviculture") #keep all elements
ffMA <- filter(ffAreas, condition1 == "Mixed_Agrisilviculture") #keep all elements
ffSP <- filter(ffAreas, condition1 == "Silvopastoral")
# zero out herbaceous, other palm, other shrub, other tree
ffSP[,c(4,5)] <- ffSP[,c(4,5)] * c(1,1,1,1,0,1,1,1,0,0,0,1,1,1,1)
# calculate group total area
ffAA <- ffA[,4] + ffBA[,4] + ffMA[,4] + ffSP[,4]
# calculate group area SE
ffAASE <- bind_cols(A = pull(ffA[,5])^2,
BA = pull(ffBA[,5])^2,
MA = pull(ffMA[,5])^2,
SP = pull(ffSP[,5])^2) %>%
rowwise() %>%
transmute(SE_ha = sum(A, BA, MA, SP, na.rm = T)) %>%
sqrt()
# assemble names, areas, SE
ffAF <- bind_cols(commodity = ffA$cover, Area_ha = pull(ffAA), SE_ha = ffAASE)
print(ffAF)
# calculate carbon stock
ffAF <- ffAF[ffAF$commodity %in% names(carbonAF),] %>%
arrange(., match(commodity, names(carbonAF))) %>%
transmute(., commodity = commodity,
Mg_C = Area_ha * carbonAF,
SE = SE_ha * carbonAF)
# Make a table
captionffAF <- c("Table X. Aboveground biomass carbon values associated with
the area of commodities in agroforestry land uses that occur in
formerly forested areas.")
kable(ffAF, caption = captionffAF, digits = 0,
col.names = c("Commodity", "MgC", "SE"))
### Calculate carbon in associated with non-AF areas
ffO <- filter(ffAreas, condition1== "Other_LAND_USE")
# zero out herbaceous, other palm, other shrub, other tree
ffO[,c(4,5)] <- ffO[,c(4,5)] * c(1,1,1,1,0,1,1,1,0,0,0,1,1,1,1)
ffP <- filter(ffAreas, condition1 == "Plantation") #keep all elements
ffT <- filter(ffAreas, condition1 == "Terrace") #keep all elements
# Calculate group total area
ffOPT <- ffO[,4] + ffP[,4] + ffT[,4]
# Calculate group area SE
ffOPTSE <- bind_cols(O = pull(ffO[,5])^2,
P = pull(ffP[,5])^2,
Tr = pull(ffT[,5])^2) %>%
rowwise() %>%
transmute(SE_ha = sum(O, P, Tr, na.rm = T)) %>%
sqrt()
# Assemble names, areas, SE
ffMono <- bind_cols(commodity = ffO$cover, Area_ha = pull(ffOPT), SE_ha = ffOPTSE)
print(ffMono)
# Calculate carbon stocks
ffMono <- ffMono[ffMono$commodity %in% names(carbonMono),] %>%
arrange(., match(commodity, names(carbonMono))) %>%
transmute(., commodity = commodity,
Mg_C = Area_ha * carbonMono,
SE = SE_ha * carbonMono)
# Make a table
captionffMono <- c("Table X. Aboveground biomass carbon values associated with
the area of commodities in monoculture plantation and terrace land
that occur in formerly forested areas.")
kable(ffMono, caption = captionffMono, digits = 0,
col.names = c("Commodity", "MgC", "SE"))
# calculate Carbon values for previously tree-covered areas --------------------
#UPDATE BELOW HERE IF TCC NEEDED
# make results into an area
# tccAreas <- arrange(cResults2, match(cover, covOrder)) %>%
# mutate(PercentCover = PercentCover * sum(stratumAreas),
# SE = SE * sum(stratumAreas))
#
# ## Agroforestry Carbon
# tccA <- tccAreas[seq(1,112,8),][-c(1,9),] #keep all elements
#
# tccBA <- tccAreas[seq(2,112,8),][-c(1,9),] #keep all elements
#
# tccMA <- tccAreas[seq(3,112,8),][-c(1,9),] #keep all elements
#
# tccSP <- tccAreas[seq(7,112,8),][-c(1,9),]
# #remove herbaceous, other palm, other shrub, other tree
# tccSP[,c(4,5)] <- tccSP[,c(4,5)] * c(1,1,1,1,1,1,1,1,0,0,0,0)
#
# tccAA <- tccA[,4] + tccBA[,4] + tccMA[,4] + tccSP[,4]
#
# tccAASE <- bind_cols(A = pull(tccA[,5])^2, BA = pull(tccBA[,5])^2,
# MA = pull(tccMA[,5])^2, SP = pull(tccSP[,5])^2) %>%
# rowwise() %>%
# transmute(SE_ha = sum(A, BA, MA, SP, na.rm = T)) %>%
# sqrt()
#
# tccAF <- bind_cols(commodity = pull(tccAreas[seq(1,112,8),1][-c(1,9),]),
# Area_ha = pull(tccAA),
# SE_ha = tccAASE)
#
# tccAF <- transmute(tccAF, commodity = commodity, Mg_C = Area_ha * carbonAF,
# SE = SE_ha * carbonAF)
#
# captiontccAF <- c("Table R13. Aboveground biomass carbon values (1,000s Mg C)
# associated with the area of commodities in agroforestry land uses that occur in
# formerly tree covered areas.")
#
# kable(tccAF, caption = captiontccAF, digits = 0,
# col.names = c("Commodity", "MgC", "SE"))
#
# ## Calculate carbon in associated with non-AF areas
# tccO <- tccAreas[seq(5,112,8),][-c(1,9),]
# #remove herbaceous, other palm, other shrub, other tree
# tccO[,c(4,5)] <- tccO[,c(4,5)] * c(1,1,1,1,1,1,1,1,0,0,0,0)
#
# tccP <- tccAreas[seq(6,112,8),][-c(1,9),] #keep all elements
#
# tccT <- tccAreas[seq(8,112,8),][-c(1,9),] #keep all elements
#
# tccOPT <- tccO[,4] + tccP[,4] + tccT[,4]
#
# tccOPTSE <- bind_cols(O = pull(tccO[,5])^2, P = pull(tccP[,5])^2,
# Tr = pull(tccT[,5])^2) %>%
# rowwise() %>%
# transmute(SE_ha = sum(O, P, Tr, na.rm = T)) %>%
# sqrt()
#
# tccMono <- bind_cols(commodity = pull(tccAreas[seq(1,112,8),1][-c(1,9),]),
# Area_ha = pull(tccOPT),
# SE_ha = tccOPTSE)
#
# tccMono <- transmute(tccMono, commodity = commodity,
# Mg_C = Area_ha * carbonMono, SE = SE_ha * carbonMono)
#
#
# captiontccMono <- c("Table R14. Aboveground biomass carbon values (1,000s Mg C)
# associated with the area of commodities in monoculture plantation and terrace
# land that occur in formerly tree-covered areas.")
#
# kable(tccMono, caption = captiontccMono, digits = 0,
# col.names = c("Commodity", "MgC", "SE"))
#+ Extra_tables ------------------------------------------------------------------
## Raw Tables
# kable(coverIn2000Area)
# kable(coverInUseArea)
# kable(useInCoverArea)
# kable(useInUse2000Area)