-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path2_global_summary.R
65 lines (58 loc) · 2.97 KB
/
2_global_summary.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
# Example of how to summarize results in Table 1 (Walker et al. 2022) from primary zonal stats table.
library(dplyr)
library(tidyr)
df <- read.csv('Global_Carbon_Summary_Table.csv')
# baseline climate, unconstrained
df %>%
select(agb_cur_mgc,agb_pot_mgc,agb_unr_mgc,bgb_cur_mgc,bgb_pot_mgc,bgb_unr_mgc,bio_cur_mgc,bio_pot_mgc,bio_unr_mgc,soc_cur_mgc,soc_pot_mgc,soc_unr_mgc,tot_cur_mgc,tot_pot_mgc,tot_unr_mgc) %>%
summarize_all(sum) %>%
mutate_all(.funs = function(x){round(x/1e9, 1)}) %>%
pivot_longer(everything(), names_to = c('.value','type'), names_pattern = '(.+)_(.+)_mgc') %>%
as.data.frame()
# baseline climate, constrained
df %>%
filter(is.na(cons_code)) %>%
select(agb_unr_mgc,bgb_unr_mgc,bio_unr_mgc,soc_unr_mgc,tot_unr_mgc) %>%
summarize_all(sum) %>%
mutate_all(.funs = function(x){round(x/1e9, 1)}) %>%
pivot_longer(everything(), names_to = c('.value','type'), names_pattern = '(.+)_(.+)_mgc') %>%
as.data.frame()
# future climate, unconstrained
df %>%
select(contains('_fc_')) %>%
summarize_all(sum) %>%
mutate_all(.funs = function(x){x/1e9}) %>%
pivot_longer(everything(), names_to = c('.value','type','.value'), names_pattern = '(.+)_(.+)_fc_(.+)_mgc') %>%
rowwise() %>%
mutate(agb_min = min(agbbc,agbcc,agbgs,agbhd,agbhe,agbip,agbmc,agbmg,agbmi,agbmr,agbno),
agb_max = max(agbbc,agbcc,agbgs,agbhd,agbhe,agbip,agbmc,agbmg,agbmi,agbmr,agbno),
bgb_min = min(bgbbc,bgbcc,bgbgs,bgbhd,bgbhe,bgbip,bgbmc,bgbmg,bgbmi,bgbmr,bgbno),
bgb_max = max(bgbbc,bgbcc,bgbgs,bgbhd,bgbhe,bgbip,bgbmc,bgbmg,bgbmi,bgbmr,bgbno),
biomean = agbmean + bgbmean,
bio_min = agb_min + bgb_min,
bio_max = agb_max + bgb_max,
agb = paste0(round(agbmean, 1), ' (', round(agb_min), '-', round(agb_max), ')'),
bgb = paste0(round(bgbmean, 1), ' (', round(bgb_min), '-', round(bgb_max), ')'),
bio = paste0(round(biomean, 1), ' (', round(bio_min), '-', round(bio_max), ')')) %>%
select(type, agb, bgb, bio) %>%
as.data.frame()
# future climate, constrained
df %>%
filter(is.na(cons_code)) %>%
select(contains('_unr_fc_')) %>%
summarize_all(sum) %>%
mutate_all(.funs = function(x){x/1e9}) %>%
pivot_longer(everything(), names_to = c('.value','type','.value'), names_pattern = '(.+)_(.+)_fc_(.+)_mgc') %>%
rowwise() %>%
mutate(agb_min = min(agbbc,agbcc,agbgs,agbhd,agbhe,agbip,agbmc,agbmg,agbmi,agbmr,agbno),
agb_max = max(agbbc,agbcc,agbgs,agbhd,agbhe,agbip,agbmc,agbmg,agbmi,agbmr,agbno),
bgb_min = min(bgbbc,bgbcc,bgbgs,bgbhd,bgbhe,bgbip,bgbmc,bgbmg,bgbmi,bgbmr,bgbno),
bgb_max = max(bgbbc,bgbcc,bgbgs,bgbhd,bgbhe,bgbip,bgbmc,bgbmg,bgbmi,bgbmr,bgbno),
biomean = agbmean + bgbmean,
bio_min = agb_min + bgb_min,
bio_max = agb_max + bgb_max,
agb = paste0(round(agbmean, 1), ' (', round(agb_min), '-', round(agb_max), ')'),
bgb = paste0(round(bgbmean, 1), ' (', round(bgb_min), '-', round(bgb_max), ')'),
bio = paste0(round(biomean, 1), ' (', round(bio_min), '-', round(bio_max), ')')) %>%
select(type, agb, bgb, bio) %>%
as.data.frame()