-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.Rmd
1381 lines (1105 loc) · 57.2 KB
/
index.Rmd
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
---
title: "GHG Emissions of the UK"
author: "Kaydee S. Barker"
date: "Mar. 2024"
output:
html_document:
toc: true
toc_float: true
---
```{r setup, include=FALSE}
rm(list=ls()) #clear global environment/workspace
knitr::opts_chunk$set(echo = FALSE, message = FALSE) #set echo and message to false universally
#knitr::knit(input = "GHG_UK.Rmd", output = "index.html")
#rmarkdown::render(input = "GHG_UK.Rmd", output_file = "index.html") #set name of knit file
```
```{r load libraries, message=FALSE}
library(readODS) #read ods files
library(readxl) #reads excel files
library(tidyverse) #Tidy packages
library(dplyr) #lots of functions - data manipulation
library(janitor) #helps with data cleaning
library(usethis) #look at and apply settings to Github actions
#library(data.tree) #transform df or file to data tree
library(ggplot2) #pretty plots
library(ggthemes) #themes for ggplot
library(RColorBrewer) #color palettes
library(wesanderson) #color palettes from Wes Anderson films
library(scales) #axis formatting options
library(plotly) #interactive web graphs
library(networkD3) #interactive web network graphs
#usethis::edit_r_environ() #set environment with Github token for API
```
## The National Atmospheric Emissions Inventory of the UK
Introduction to the inventory, with links megatonnes of CO2 equivalents Territorial Emissions Statistics (TES) sectors and subsectors used, as they are replacing National Communications (NC) sectors and subsectors in all reports (<https://www.gov.uk/government/statistics/final-uk-greenhouse-gas-emissions-national-statistics-1990-to-2022>)
```{r load data, warning=FALSE}
#Map loop to download UK 2022 data from the UK Department for Energy Security and Net Zero
downloaded <- file.exists("UKGHG_2022.ods") #checks if file is downloaded in working directory
if(downloaded != T){ #if downloaded is not true
map2("https://assets.publishing.service.gov.uk/media/65c0d54663a23d000dc821ca/final-greenhouse-gas-emissions-2022-by-source-dataset.ods", #update this link when new data available
"UKGHG_2022.ods", download.file)} #else{print('data downloaded')} #name and download or print
#Read in ods file
GHG_UK22 <- read_ods(
path = "UKGHG_2022.ods",
sheet = 1, #define tab/sheet to read
col_names = TRUE, #use header row for column names
col_types = NULL, #guess data types
na = "", #treat blank cells as NA
skip = 0, #don't skip rows
formula_as_formula = FALSE, #values only
range = NULL,
row_names = FALSE, #no row names
strings_as_factors = TRUE) %>% #use factors
clean_names() %>% #clean column names to lowercase, with underscores
separate_wider_delim(source, delim = " - ", #separate source, define delimiter as " - "
names = c("source_1", "source_2", "source_3"), #name new columns
too_few = "align_start", too_many = "merge", #what to do with fewer or more than 3
cols_remove = FALSE) %>% #keep original column
separate_wider_delim(tes_category, delim = " - ", #separate category, define delimiter as " - "
names = c("category_1", "category_2"), #name new columns
too_few = "align_start", too_many = "merge", #what to do with fewer or more than 2
cols_remove = FALSE) %>% #keep original column
separate_wider_delim(activity, delim = " - ", #separate activity, define delimiter as " - "
names = c("activity_1", "activity_2"), #name new columns
too_few = "align_start", too_many = "merge", #what to do with fewer or more than 2
cols_remove = FALSE) %>% #keep original column
replace(is.na(.), "") #get rid of NA values, input blank
#Map loop to download UK sector mapping data
downloaded2 <- file.exists("UKsectors.xlsx") #checks if file is downloaded in working directory
if(downloaded2 != T){ #if downloaded is not true
map2("https://assets.publishing.service.gov.uk/media/65c0d392c4319100141a455d/ghg-statistics-tes-to-nc-sector-mapping-2022.xlsx", #update this link when new data available
"UKsectors.xlsx", download.file)} #else{print('data downloaded')} #name and download or print
#Read in excel file
UKsectors <- read_xlsx(
"UKsectors.xlsx", #excel file from current working directory
sheet = "Table 1", #define tab/sheet to read
col_names = FALSE, #the format of this excel file doesn't allow headers to be column names
col_types = NULL, #guess data types
na = "", #treat blank cells as NA
trim_ws = TRUE, #trim any whitespace/unused columns and rows
skip = 6, #skip 6 rows to get to pivot table data
n_max = Inf, #set maximum number of rows to include
guess_max = min(1000, Inf), #how many rows to use to guess data types
progress = readxl_progress(), #display progress in reading in data
.name_repair = "unique" #makes sure all column names not empty or duplicated
)
#Assign headers/column names for UK sectors dataframe (doesn't import with headers)
colnames(UKsectors) <- c("ipcc_code", "source", "activity", "nc_sector", "nc_subsector", "nc_category",
"tes_sector", "tes_subsector", "tes_category")
#Assign more specific codes than IPCC codes
UKsectors <- UKsectors %>%
mutate(subcode = case_when(tes_subsector == "Bioenergy crops" ~ "a", #create a subcode for LULUCF subsectors
tes_subsector == "Cropland mineral soils change" ~ "b",
tes_subsector == "Forestry" ~ "c",
tes_subsector == "Grassland mineral soils change" ~ "d",
tes_subsector == "Peatland" ~ "e",
tes_subsector == "Settlement" ~ "f",
tes_subsector == "Other LULUCF" ~ "g",
.default = "")) %>%
unite('ipcc_code2', c(ipcc_code, subcode), remove = FALSE, sep = "_") #combine IPCC code with subcode
IPCC_TES <- UKsectors[, c(1,2,8,9,10)] #dataframe with just IPCC codes and TES sectors, subsectors, and categories
#Map loop to download UK Regional data 1990-2022 from the UK National Atmospheric Emissions Inventory
downloaded3 <- file.exists("GHG_regions.xlsx") #checks if file is downloaded in working directory
if(downloaded3 != T){ #if downloaded is not true
map2("https://uk-air.defra.gov.uk/reports/cat09/2306200930_DA_GHGI_1990-2022_Final_v3.1.xlsx", #update this link when new data available
"GHG_regions.xlsx", download.file)} #else{print('data downloaded')} #name and download or print
#Read in excel file, by source, with region
GHG_regions <- read_xlsx(
"GHG_regions.xlsx", #excel file from current working directory
sheet = "BySource_data", #define tab/sheet to read
col_names = TRUE, #use header row for column names
col_types = NULL, #guess data types
na = "", #treat blank cells as NA
trim_ws = TRUE, #trim any whitespace/unused columns and rows
skip = 6, #skip 6 rows to get to pivot table data
n_max = Inf, #set maximum number of rows to include
guess_max = min(1000, Inf), #how many rows to use to guess data types
progress = readxl_progress(), #display progress in reading in data
.name_repair = "unique" #makes sure all column names not empty or duplicated
) %>%
clean_names() %>% #clean column names to lowercase, with underscores
separate_wider_delim(source_name, delim = " - ", #separate source, define delimiter as " - "
names = c("source_1", "source_2", "source_3"), #name new columns
too_few = "align_start", too_many = "merge", #what to do with fewer or more than 3
cols_remove = FALSE) #keep original column
GHG_regions$ipcc_name <- gsub('_', ' ', GHG_regions$ipcc_name) #replace string underscores with spaces
#Look at distinct instances of codes and categories in regional dataset
GHG_codes <- GHG_regions[, c(5:9)] %>%
distinct()
#Assign more specific codes than IPCC codes
#LULUCF TES Subsectors search strings
Bioenergy <- c("Bioenergy crops", "Miscanthus", "coppice")
Cropland <- c("Remaining Cropland", "converted to Cropland")
Forestry <- c("remaining Forest Land", "converted to Forest Land", "converted from forest land", "Harvested Wood")
Grassland <- c("Remaining Grassland", "converted to Grassland")
Peatland <- c("drain", "wet", "peat")
Settlement <- c("converted to settlement")
O_LULUCF <- c("Biomass Burning","carbon stock change")
#Assign codes from strings
GHG_regions <- GHG_regions %>%
mutate(subcode = case_when(grepl(paste(Bioenergy, collapse='|'), source_name, ignore.case = TRUE) ~ "a", #for LULUCF
grepl(paste(Cropland, collapse='|'), source_name, ignore.case = TRUE) ~ "b",
grepl(paste(Forestry, collapse='|'), source_name, ignore.case = TRUE) ~ "c",
grepl(paste(Grassland, collapse='|'), source_name, ignore.case = TRUE) ~ "d",
grepl(paste(Peatland, collapse='|'), source_name, ignore.case = TRUE) ~ "e",
grepl(paste(Settlement, collapse='|'), source_name, ignore.case = TRUE) ~ "f",
grepl(paste(O_LULUCF, collapse='|'), source_name, ignore.case = TRUE) ~ "g",
.default = "")) %>%
unite('ipcc_code2', c(ipcc_code, subcode), remove = FALSE, sep = "_") #combine IPCC code with subcode
#Add subsector into GHG_regions, match format, add more specific IPCC codes to join by
GHG_regions2 <- inner_join(IPCC_TES, GHG_regions,
by=c("ipcc_code2", "ipcc_code")) %>% #use inner join to combine dataframes by shared variables
rename("ghg_grouped" = "pollutant") %>% #rename variable to match UK only csv
rename("nc_sector" = "nc_format") #rename variable
#Newest years only
#UK-wide dataset
GHG_UK2022 <- GHG_UK22 %>%
filter(year == "2022") #%>%
#filter(tes_sector != "LULUCF") #filter out LULUCF to see if negative values impact things
GHG_UK2022pos <- GHG_UK2022 %>%
filter(emissions_mt_co2e >= "0") #subset filter only positive values
#Regional dataset
GHG_regions2021 <- GHG_regions2 %>%
filter(emission_year == "2021")
#Simplify
GHG_simp <- GHG_UK2022 %>%
group_by(tes_sector, tes_subsector, category_2, category_1, activity) %>%
summarize(Temissions = sum(emissions_mt_co2e, na.rm = TRUE)) %>%
replace(is.na(.), "") %>%
filter(Temissions >= "0") #subset filter only positive values
#Pivot - rows are greenhouse gas groups
GHG_wide <- GHG_UK22 %>%
pivot_wider(names_from = ghg_grouped, values_from=emissions_mt_co2e) %>%
replace(is.na(.), 0)
```
## Visualization at High Level
```{r vis set up, warning=FALSE}
#Define custom color palette
colors <- c(
"#3CBD9C", #transport
"#F0A7CA", #buildings
"#F0C954", #industry
"#C24841", #electricity
"#96BC61", #ag green
"#5D7ED1", #lulucf blue
"#D38744", #fuel
"#A780BB" #waste purple
)
colors_3lvls <- c(
"#C24841", #CH4
"#3CBD9C", #CO2
"#F0C954" #N2O
)
```
### Sunburst Diagram of Emissions
```{r emissions sunburst, warning=FALSE, fig.align = "center", out.width = '95%', fig.cap="Sunburst diagram demonstrating proportional breakdown of greenhouse gas emissions in the UK in 2022."}
#Format data for sunburst
#Separate out variables summaries - all GHGs combined
sectors <- GHG_UK2022pos %>%
group_by(tes_sector) %>%
summarize(Temissions = sum(emissions_mt_co2e, na.rm = TRUE))
subsectors <- GHG_UK2022pos %>%
group_by(tes_sector, tes_subsector) %>%
summarize(Temissions = sum(emissions_mt_co2e, na.rm = TRUE))
cat_2 <- GHG_UK2022pos %>%
filter(category_2 != "") %>%
group_by(tes_sector, tes_subsector, category_2) %>%
summarize(Temissions = sum(emissions_mt_co2e, na.rm = TRUE)) %>%
unite('parents', c(tes_sector, tes_subsector), remove = TRUE, sep = " - ") #combine higher categories into parents
cat_1 <- GHG_UK2022pos %>%
group_by(tes_sector, tes_subsector, category_2, category_1) %>%
summarize(Temissions = sum(emissions_mt_co2e, na.rm = TRUE)) %>%
mutate(parents = case_when(
category_2 != "" ~str_c(tes_sector,tes_subsector,category_2, sep = " - "),
category_2 == "" ~str_c(tes_sector,tes_subsector, sep = " - ")))
act_1 <- GHG_UK2022pos %>%
group_by(tes_sector, tes_subsector, category_2, category_1, activity_1) %>%
summarize(Temissions = sum(emissions_mt_co2e, na.rm = TRUE)) %>%
mutate(parents = case_when(
category_2 != "" ~str_c(tes_sector,tes_subsector,category_2, category_1, sep = " - "),
category_2 == "" ~str_c(tes_sector,tes_subsector, category_1, sep = " - ")
))
act_2 <- GHG_UK2022pos %>%
filter(activity_2 != "") %>%
group_by(tes_sector, tes_subsector, category_2, category_1, activity_1, activity_2) %>%
summarize(Temissions = sum(emissions_mt_co2e, na.rm = TRUE)) %>%
mutate(parents = case_when(
category_2 != "" ~str_c(tes_sector,tes_subsector,category_2, category_1, activity_1, sep = " - "),
category_2 == "" ~str_c(tes_sector,tes_subsector, category_1, activity_1, sep = " - ")
))
#Now paste together distinct instances into dataframe with hierarchical structure - start simple, set root
GHGsb1 <- data.frame(
parents =c(rep("", 8)),
labels =c(paste0(sectors$tes_sector)),
values =as.numeric(c(paste0(sectors$Temissions)))
)
#Add id column
GHGsb1 <- GHGsb1 %>%
mutate(ids = labels)
#Now paste together distinct instances into dataframe with hierarchical structure - add on
GHGsb2 <- data.frame(
parents =c(paste0(subsectors$tes_sector), paste0(cat_2$parents), paste0(cat_1$parents),
paste0(act_1$parents), paste0(act_2$parents)),
labels =c(paste0(subsectors$tes_subsector), paste0(cat_2$category_2), paste0(cat_1$category_1),
paste0(act_1$activity_1), paste0(act_2$activity_2)),
values =as.numeric(c(paste0(subsectors$Temissions), paste0(cat_2$Temissions), paste0(cat_1$Temissions), paste0(act_1$Temissions), paste0(act_2$Temissions)))
)
#Add id column
GHGsb2 <- GHGsb2 %>%
unite('ids', c(parents, labels), remove = FALSE, sep = " - ") #combine columns for id
#Combine into one dataframe
GHGsb <- rbind(GHGsb1, GHGsb2)
#Interactive sunburst with Plotly
sb <- plot_ly(GHGsb,
type = 'sunburst',
ids = ~ids,
labels = ~labels,
parents = ~parents,
values = ~values,
branchvalues = 'total', #parents are totals of children
insidetextorientation='radial',
maxdepth = 2, #how many levels to show
level = "",
sort = TRUE #sort by size
#width = 800, height = 800 #plot dimensions
) %>%
layout(
margin = list(l = 10, r = 10, b = 10, t = 10),
sunburstcolorway = colors,
extendsunburstcolors = TRUE
)
style(sb, hovertemplate="%{label}
%{value:,.3r} Mt CO2 equivalents
%{percentParent:.1%} of %{parent} emissions
<extra></extra>")
```
### Sunburst Diagram of Removals
```{r removals sunburst, warning=FALSE, fig.align = "center", out.width = '65%', fig.cap="Sunburst diagram demonstrating proportional breakdown of greenhouse gas removals in the UK (Land Use, Land Use Change, and Forestry Sector) in 2022."}
#Format data for sunburst
GHG_UK2022neg <- GHG_UK2022 %>%
filter(emissions_mt_co2e <= "0") #subset filter only negative values
GHG_UK2022neg$source_2[c(6:8,13,14)] <- GHG_UK2022neg$source_1[c(6:8,13,14)] #replace empty source 2 values with source 1
#Separate out variables summaries - all GHGs combined
subsectors_neg <- GHG_UK2022neg %>%
group_by(tes_subsector) %>%
summarize(Temissions = sum(emissions_mt_co2e, na.rm = TRUE))
cat_neg <- GHG_UK2022neg %>%
group_by(tes_subsector, tes_category) %>%
summarize(Temissions = sum(emissions_mt_co2e, na.rm = TRUE))
src_neg <- GHG_UK2022neg %>%
group_by(tes_subsector, tes_category, source_2) %>%
summarize(Temissions = sum(emissions_mt_co2e, na.rm = TRUE)) %>%
unite('parents', c(tes_subsector, tes_category), remove = TRUE, sep = " - ") #combine higher categories into parents
#Now paste together distinct instances into dataframe with hierarchical structure - start simple, set root
GHGsb1_neg <- data.frame(
parents =c(rep("", 6)),
labels =c(paste0(subsectors_neg$tes_subsector)),
values =as.numeric(c(paste0(subsectors_neg$Temissions)))
)
#Add id column
GHGsb1_neg <- GHGsb1_neg %>%
mutate(ids = labels)
#Now paste together distinct instances into dataframe with hierarchical structure - add on
GHGsb2_neg <- data.frame(
parents =c(paste0(cat_neg$tes_subsector), paste0(src_neg$parents)),
labels =c(paste0(cat_neg$tes_category), paste0(src_neg$source_2)),
values =as.numeric(c(paste0(cat_neg$Temissions), paste0(src_neg$Temissions)))
)
#Add id column
GHGsb2_neg <- GHGsb2_neg %>%
unite('ids', c(parents, labels), remove = FALSE, sep = " - ") #combine columns for id
#Combine into one dataframe
GHGsb_neg <- rbind(GHGsb1_neg, GHGsb2_neg)
#Convert negative values to absolute (positive) values
GHGsb_neg$values <- abs(GHGsb_neg$values)
#Interactive sunburst with Plotly
sb_neg <- plot_ly(GHGsb_neg,
type = 'sunburst',
ids = ~ids,
labels = ~labels,
parents = ~parents,
values = ~values,
branchvalues = 'total', #parents are totals of children
insidetextorientation='radial',
maxdepth = 2, #how many levels to show
level = "",
sort = TRUE #sort by size
#width = 800, height = 800 #plot dimensions
) %>%
layout(
margin = list(l = 10, r = 10, b = 10, t = 10),
sunburstcolorway = c(
"#3CBD9C", #forestry
"#F0C954", #grassland
"#5D7ED1", #peatland
"#C24841", #cropland
"#96BC61",
"#F0A7CA",
"#D38744",
"#A780BB"
),
extendsunburstcolors = TRUE
)
style(sb_neg, hovertemplate="%{label}
%{value:,.3r} Mt CO2 equivalents
%{percentParent:.1%} of %{parent} removals
<extra></extra>")
```
### Time Series Graph of Net Emissions by Sector
```{r time series, warning=FALSE, fig.align = "center", out.width = '95%', fig.cap="Greenhouse gas emissions in megatonnes of CO2 equivalents in the UK over time, by sector."}
#Plot time series
Sect_time <- GHG_UK22 %>%
group_by(year, tes_sector) %>%
summarize(Temissions = sum(emissions_mt_co2e, na.rm = TRUE)) %>%
rename("Sector" = "tes_sector") %>% #rename variable
pivot_wider(names_from = Sector, values_from=Temissions) %>%
clean_names() %>%
droplevels() %>%
ungroup() %>%
plot_ly(x = ~year,
y = ~agriculture, name = "Agriculture", line = list(color = "#96BC61", width = 2),
type = 'scatter', mode = 'lines') %>%
add_trace(y = ~buildings_and_product_uses, name = 'Buildings and product uses', line = list(color ="#F0A7CA", width = 2)) %>%
add_trace(y = ~domestic_transport, name = 'Domestic transport', line = list(color ="#3CBD9C", width = 2)) %>%
add_trace(y = ~electricity_supply, name = 'Electricity supply', line = list(color ="#C24841", width = 2)) %>%
add_trace(y = ~fuel_supply, name = 'Fuel supply', line = list(color ="#D38744", width = 2)) %>%
add_trace(y = ~industry, name = 'Industry', line = list(color ="#F0C954", width = 2)) %>%
add_trace(y = ~lulucf, name = 'Land Use, Land Use Change, and Forestry', line = list(color ="#5D7ED1", width = 2)) %>%
add_trace(y = ~waste, name = 'Waste', line = list(color ="#A780BB", width = 2)) %>%
layout(title = "Greenhouse Gas Emissions of the UK per Sector Over Time",
xaxis = list(title = ""),
yaxis = list(title = "Greenhouse Gas Emissions (Megatonnes CO2 eq.)"),
legend = list(orientation = "h"))
#Plotly customization
style(Sect_time, hovertemplate="Year: %{x:,.r}
CO2eq: %{y:,.4r} kt") #define what hover label says, round x values, round y values to 4 sig. figs
```
## Sector and Subsector Summaries
### Agriculture
```{r ag sankey1, eval=FALSE, include=FALSE, fig.align = "center", out.width = '95%', fig.cap="Sankey diagram demonstrating breakdown of greenhouse gas emissions in the UK's agricultural sector in 2022."}
ag_df <- GHG_UK2022 %>%
filter(tes_sector == "Agriculture") %>% #filter sector
replace(is.na(.), "")
#group_by(tes_subsector, tes_category, source, ghg, ghg_grouped, ipcc_code) %>%
#summarize(Temissions = sum(emissions_mt_co2e, na.rm = TRUE))
#Set up Sankey links dataframe
aglinks <- data.frame(source=c(paste0(ag_df$ghg_grouped), paste0(ag_df$tes_subsector), paste0(ag_df$category_2)),
target=c(paste0(ag_df$tes_subsector), paste0(ag_df$category_2), paste0(ag_df$category_1)),
value=as.numeric(paste0(ag_df$emissions_mt_co2e)))
#Create nodes df from names in links df
agnodes <- data.frame(
name=unique(c(as.character(aglinks$source),
as.character(aglinks$target))))
#Add ID numbers
aglinks$IDsource <- as.numeric(match(aglinks$source, agnodes$name)-1)
aglinks$IDtarget <- as.numeric(match(aglinks$target, agnodes$name)-1)
#Plot with networkD3
agsankey <- sankeyNetwork(Links = aglinks, Nodes = agnodes,
Source = "IDsource", Target = "IDtarget",
Value = "value", NodeID = "name",
units = "Megatonnes CO2 eq.",
sinksRight=FALSE, nodePadding = 8,
iterations = 5)
agsankey
```
```{r ag sankey2, eval=FALSE, include=FALSE}
#Plot with Plotly
agsankey2 <- plot_ly(type = "sankey",
domain = list(x = c(0,1),y = c(0,1)),
orientation = "h",
valueformat = ".0f",
valuesuffix = "Mt CO2 eq.",
node = list(
label = agnodes$name,
pad = 15,
thickness = 20,
line = list(color = "black", width = 0.5),
link = list(
source = aglinks$IDsource,
target = aglinks$IDtarget,
value = aglinks$value
#label = linklist$label
))) %>%
layout(
title = "Greenhouse Gas Emissions Per Agriculture Subsector in the UK",
font = list(size = 10),
xaxis = list(showgrid = F, zeroline = F),
yaxis = list(showgrid = F, zeroline = F))
agsankey2
```
#### Agriculture Breakdown Graphs
```{r ag pies, eval=FALSE, include=FALSE, warning=FALSE, fig.align = "center", out.width = '95%', fig.cap="Doughnut charts of the UK's agriculture greenhouse gas emissions by greenhouse gas identity and subsector in 2022."}
agpie <- ag_df %>% plot_ly(textinfo = 'label', insidetextorientation='horizontal') %>%
add_pie(labels = ~ghg, values = ~emissions_mt_co2e, hole = 0.6, domain = list(row = 0, column = 0)) %>%
add_pie(labels = ~tes_subsector, values = ~emissions_mt_co2e, hole = 0.6, domain = list(row = 0, column = 2)) %>%
layout(title = "Emissions by Greenhouse Gas Identity and Subsector", showlegend = F,
#annotations = list(list(x = 0.20 , y = 1, text = "Emissions by Greenhouse Gas Identity"),
# list(x = 0.80 , y = 1, text = "Emissions by Subsector")),
colorscale = colors,
grid=list(rows=1, columns=3),
xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))
style(agpie, hovertemplate="%{label}
Emissions: %{value:,.4r} Mt CO2 eq.
%{percent}
<extra></extra>")
```
```{r ag facet grid, eval=FALSE, include=FALSE, warning=FALSE, fig.align = "center", out.width = '95%', fig.cap="Bar graph showing greenhouse gas emissions in megatonnes of CO2 equivalents in the UK's agricultural sector in by category, colored by subsector and grouped by greenhouse gas identity."}
#Plot GHGs into side-by-side plots with Plotly
ag_CO2 <- agwideGHG %>%
plot_ly(x = ~tes_category, y = ~CO2, color = ~tes_subsector, type = 'bar',
legendgroup = ~tes_subsector) %>%
layout(xaxis = list(showticklabels=FALSE, showgrid = FALSE))
ag_CH4 <- agwideGHG %>%
plot_ly(x = ~tes_category, y = ~CH4, color = ~tes_subsector, type = 'bar',
legendgroup = ~tes_subsector, showlegend = F) %>%
layout(xaxis = list(showticklabels=FALSE, showgrid = FALSE))
ag_N2O <- agwideGHG %>%
plot_ly(x = ~tes_category, y = ~N2O, color = ~tes_subsector, type = 'bar',
legendgroup = ~tes_subsector, showlegend = F) %>%
layout(xaxis = list(showticklabels=FALSE, showgrid = FALSE))
ag_GHGs <- subplot(ag_CO2, ag_CH4, ag_N2O, shareY = FALSE, margin = 0.05) %>%
layout(title = list(text = "UK's Agriculture Emissions in 2022", pad = list(t=50, b = 50)),
yaxis = list(title = 'Emissions (Mt CO2 eq.)'),
plot_bgcolor='#e5ecf6',
legend = list(orientation = "h", title=list(text='<b>Subsector</b>')),
annotations = list(list(
x = 0.125, y = 1.0,
text = "CO2",
xref = "paper",
yref = "paper",
showarrow = FALSE),
list(
x = 0.5, y = 1.0,
text = "CH4",
xref = "paper",
yref = "paper",
showarrow = FALSE),
list(
x = 0.875, y = 1.0,
text = "N2O",
xref = "paper",
yref = "paper",
showarrow = FALSE)))
#Plotly customization
style(ag_GHGs,
hovertemplate="Source: %{x}
Emissions: %{y:,.4r} Mt CO2 eq.") #define what hover label says, round x values, round y values to 4 sig. figs
```
```{r ag subsectors, warning=FALSE, fig.align = "center", out.width = '95%', fig.cap="Bar graph showing greenhouse gas emissions in megatonnes of CO2 equivalents in the UK's agriculture sector in 2022 by subsector, stacked by greenhouse gas identity."}
#Bar plot by subsector, stacked by GHG with Plotly
agbar_int <- GHG_UK2022 %>%
filter(tes_sector == "Agriculture") %>%
group_by(tes_subsector, ghg, ghg_grouped) %>%
summarize(Temissions = sum(emissions_mt_co2e, na.rm = TRUE)) %>%
pivot_wider(names_from = ghg_grouped, values_from=Temissions) %>%
droplevels() %>%
plot_ly(x = ~tes_subsector, type = 'bar', y = ~CO2, name = 'CO2', marker = list(color ="#3CBD9C")) %>%
add_trace(y = ~CH4, name = 'CH4', marker = list(color ="#C24841")) %>%
add_trace(y = ~N2O, name = 'N2O', marker = list(color ="#D38744")) %>%
layout(yaxis = list(title = 'Emissions (Mt CO2 eq.)'),
barmode = 'stack'
)
#Plotly customization
style(agbar_int, hovertemplate="Subsector: %{x}
Emissions: %{y:,.4r} Mt CO2 eq.") #define what hover label says, round x values, round y values to 4 sig. figs
```
```{r ag categories 1, warning=FALSE, fig.align = "center", out.width = '95%', fig.cap="Bar graph showing greenhouse gas emissions in megatonnes of CO2 equivalents in the UK's agriculture sector in 2022 by category, filled by subsector."}
#Bar plot by category, filled by subsector with Plotly
agcat_int <- GHG_UK2022 %>%
filter(tes_sector == "Agriculture") %>%
group_by(tes_subsector, tes_category) %>%
summarize(Temissions = sum(emissions_mt_co2e, na.rm = TRUE)) %>%
droplevels() %>%
plot_ly(x = ~tes_category, type = 'bar', y = ~Temissions, color = ~tes_subsector, colors = colors,
marker = list(
width = 1.5)) %>%
layout(title = 'Agriculture Emissions by TES Subsector and Category',
yaxis = list(title = 'Emissions (Mt CO2 eq.)'),
xaxis = list(title = '', tickangle = -90),
legend = list(x = 0.8, y = 1, orientation = 'v'),
autosize = F, width = 1000, height = 600,
autoexpand = T,
barmode = 'group'
)
#Plotly customization
style(agcat_int,
hovertemplate="Category: %{x}
Emissions: %{y:,.4r} Mt CO2 eq.") #define what hover label says, round x values, round y values to 4 sig. figs
```
##### Subsector GHGs
```{r ag c, warning=FALSE, fig.align = "center", out.width = '95%', fig.cap="Bar graph showing greenhouse gas emissions in megatonnes of CO2 equivalents in the agricultural combustion subsector in 2022 by category, stacked by fuel type."}
#Bar plot combustion, stacked by fuel type with Plotly
agcom_int <- GHG_UK2022 %>%
filter(tes_sector == "Agriculture") %>%
filter(tes_subsector == "Agricultural combustion") %>%
group_by(category_1, activity) %>%
summarize(Temissions = sum(emissions_mt_co2e, na.rm = TRUE)) %>%
pivot_wider(names_from = activity, values_from=Temissions) %>%
clean_names() %>%
droplevels() %>%
plot_ly(x = ~category_1, type = 'bar', y = ~gas_oil, name = 'Gas oil', marker = list(color ="#C24841")) %>%
add_trace(y = ~petrol, name = 'Petrol', marker = list(color ="#A780BB")) %>%
add_trace(y = ~biogas, name = 'Biogas', marker = list(color ="#3CBD9C")) %>%
add_trace(y = ~burning_oil, name = 'Burning oil', marker = list(color ="#F0A7CA")) %>%
add_trace(y = ~fuel_oil, name = 'Fuel oil', marker = list(color ="#D38744")) %>%
add_trace(y = ~natural_gas, name = 'Natural gas', marker = list(color ="#5D7ED1")) %>%
add_trace(y = ~straw, name = 'Straw', marker = list(color ="#F0C954")) %>%
layout(title = 'Agricultural Combustion Emissions by Fuel Type',
yaxis = list(title = 'Emissions (Mt CO2 eq.)'),
xaxis = list(title = ''),
barmode = 'stack'
)
#Plotly customization
style(agcom_int,
hovertemplate="Source: %{x}
Emissions: %{y:,.4r} Mt CO2 eq.") #define what hover label says, round x values, round y values to 4 sig. figs
```
```{r ag soil, warning=FALSE, fig.align = "center", out.width = '95%', fig.cap="Bar graph showing greenhouse gas emissions in megatonnes of CO2 equivalents in the agricultural soils subsector in 2022 by category, stacked by greenhouse gas identity."}
#Bar plot soil, stacked by GHG with Plotly
agsoil_int <- GHG_UK2022 %>%
filter(tes_sector == "Agriculture") %>%
filter(tes_subsector == "Agricultural soils") %>%
group_by(tes_category, ghg) %>%
summarize(Temissions = sum(emissions_mt_co2e, na.rm = TRUE)) %>%
pivot_wider(names_from = ghg, values_from=Temissions) %>%
droplevels() %>%
plot_ly(x = ~tes_category, type = 'bar', y = ~CO2, name = 'CO2', marker = list(color ="#3CBD9C")) %>%
add_trace(y = ~N2O, name = 'N2O', marker = list(color ="#D38744")) %>%
layout(title = 'Agricultural Soil Emissions by Category',
yaxis = list(title = 'Emissions (Mt CO2 eq.)'),
xaxis = list(title = ''),
barmode = 'stack'
)
#Plotly customization
style(agsoil_int,
hovertemplate="Source: %{x}
Emissions: %{y:,.4r} Mt CO2 eq.") #define what hover label says, round x values, round y values to 4 sig. figs
```
```{r livestock1, warning=FALSE, fig.align = "center", out.width = '95%', fig.cap="Bar graph showing greenhouse gas emissions in megatonnes of CO2 equivalents in the livestock subsector in 2022 by category, stacked by greenhouse gas identity."}
#Bar plot livestock animals, stacked by GHG with Plotly
agls_int <- GHG_UK2022 %>%
filter(tes_sector == "Agriculture") %>%
filter(tes_subsector == "Livestock") %>%
group_by(category_1, ghg) %>%
summarize(Temissions = sum(emissions_mt_co2e, na.rm = TRUE)) %>%
pivot_wider(names_from = ghg, values_from=Temissions) %>%
droplevels() %>%
plot_ly(x = ~category_1, type = 'bar', y = ~CH4, name = 'CH4', marker = list(color ="#C24841")) %>%
add_trace(y = ~N2O, name = 'N2O', marker = list(color ="#D38744")) %>%
layout(title = 'Agricultural Livestock Emissions by Category',
yaxis = list(title = 'Emissions (Mt CO2 eq.)'),
xaxis = list(title = ''),
barmode = 'stack'
)
#Plotly customization
style(agls_int,
hovertemplate="Source: %{x}
Emissions: %{y:,.4r} Mt CO2 eq.") #define what hover label says, round x values, round y values to 4 sig. figs
```
```{r livestock2, warning=FALSE, fig.align = "center", out.width = '95%', fig.cap="Bar graph showing greenhouse gas emissions in megatonnes of CO2 equivalents in the livestock subsector in 2022 by category, stacked by animal kind."}
#Bar plot livestock category, stacked by animal with Plotly
agls2_int <- GHG_UK2022 %>%
filter(tes_sector == "Agriculture") %>%
filter(tes_subsector == "Livestock") %>%
group_by(category_1, category_2) %>%
summarize(Temissions = sum(emissions_mt_co2e, na.rm = TRUE)) %>%
pivot_wider(names_from = category_2, values_from=Temissions) %>%
clean_names() %>%
droplevels() %>%
plot_ly(x = ~category_1, type = 'bar', y = ~beef_cattle, name = 'Beef cattle', marker = list(color ="#C24841")) %>%
add_trace(y = ~dairy_cattle, name = 'Dairy cattle', marker = list(color ="#D38744")) %>%
add_trace(y = ~sheep, name = 'Sheep', marker = list(color ="#96BC61")) %>%
add_trace(y = ~pigs, name = 'Pigs', marker = list(color ="#F0A7CA")) %>%
add_trace(y = ~poultry, name = 'Poultry', marker = list(color ="#A780BB")) %>%
add_trace(y = ~other_livestock, name = 'Other livestock', marker = list(color ="#3CBD9C")) %>%
layout(title = 'Agricultural Livestock Emissions by Category and Animal',
yaxis = list(title = 'Emissions (Mt CO2 eq.)'),
xaxis = list(title = ''),
barmode = 'stack'
)
#Plotly customization
style(agls2_int,
hovertemplate="Source: %{x}
Emissions: %{y:,.4r} Mt CO2 eq.") #define what hover label says, round x values, round y values to 4 sig. figs
```
```{r livestock3, warning=FALSE, fig.align = "center", out.width = '95%', fig.cap="Bar graph showing greenhouse gas emissions in megatonnes of CO2 equivalents in the livestock subsector in 2022 by animal, stacked by greenhouse gas identity."}
#Bar plot livestock animals, stacked by GHG with Plotly
agls3_int <- GHG_UK2022 %>%
filter(tes_sector == "Agriculture") %>%
filter(tes_subsector == "Livestock") %>%
group_by(category_2, ghg) %>%
summarize(Temissions = sum(emissions_mt_co2e, na.rm = TRUE)) %>%
pivot_wider(names_from = ghg, values_from=Temissions) %>%
droplevels() %>%
plot_ly(x = ~category_2, type = 'bar', y = ~CH4, name = 'CH4', marker = list(color ="#C24841")) %>%
add_trace(y = ~N2O, name = 'N2O', marker = list(color ="#D38744")) %>%
layout(title = 'Agricultural Livestock Emissions by Animal',
yaxis = list(title = 'Emissions (Mt CO2 eq.)'),
xaxis = list(title = ''),
barmode = 'stack'
)
#Plotly customization
style(agls3_int,
hovertemplate="Source: %{x}
Emissions: %{y:,.4r} Mt CO2 eq.") #define what hover label says, round x values, round y values to 4 sig. figs
```
```{r, warning=FALSE, fig.align = "center", out.width = '95%', fig.cap="Bar graph showing greenhouse gas emissions in megatonnes of CO2 equivalents in the agricultural 'other' subsector in 2022 by category, stacked by greenhouse gas identity."}
#Bar plot other ag, stacked by GHG
agother_int <- GHG_UK2022 %>%
filter(tes_sector == "Agriculture") %>%
filter(tes_subsector == "Other agriculture") %>%
group_by(tes_category, ghg) %>%
summarize(Temissions = sum(emissions_mt_co2e, na.rm = TRUE)) %>%
pivot_wider(names_from = ghg, values_from=Temissions) %>%
droplevels() %>%
plot_ly(x = ~tes_category, type = 'bar', y = ~CO2, name = 'CO2', marker = list(color ="#3CBD9C")) %>%
layout(title = 'Other Agricultural Emissions',
yaxis = list(title = 'Emissions (Mt CO2 eq.)'),
xaxis = list(title = ''),
barmode = 'stack'
)
#Plotly customization
style(agother_int,
hovertemplate="Source: %{x}
Emissions: %{y:,.4r} Mt CO2 eq.") #define what hover label says, round x values, round y values to 4 sig. figs
```
### LULUCF
```{r, eval=FALSE, include=FALSE, fig.align = "center", out.width = '95%', fig.cap="Sankey diagram demonstrating breakdown of greenhouse gas emissions in the UK's LULUCF sector in 2022."}
LULUCF <- GHG_UK2022 %>%
filter(tes_sector == "LULUCF") %>% #filter sector
replace(is.na(.), "")
#group_by(tes_subsector, tes_category, source, ghg, ghg_grouped, ipcc_code) %>%
#summarize(Temissions = sum(emissions_mt_co2e, na.rm = TRUE))
#Set up Sankey links dataframe
LULUCFlinks <- data.frame(source=c(paste0(LULUCF$ghg)),
target=c(paste0(LULUCF$tes_subsector)),
value=as.numeric(paste0(LULUCF$emissions_mt_co2e)))
#Create nodes df from names in links df
LULUCFnodes <- data.frame(
name=unique(c(as.character(LULUCFlinks$source),
as.character(LULUCFlinks$target))))
#Add ID numbers
LULUCFlinks$IDsource <- as.numeric(match(LULUCFlinks$source, LULUCFnodes$name)-1)
LULUCFlinks$IDtarget <- as.numeric(match(LULUCFlinks$target, LULUCFnodes$name)-1)
#Plot with networkD3
LULUCFsankey <- sankeyNetwork(Links = LULUCFlinks, Nodes = LULUCFnodes,
Source = "IDsource", Target = "IDtarget",
Value = "value", NodeID = "name",
units = "Mt CO2 eq.",
sinksRight=TRUE, nodePadding = 30,
iterations = 100)
LULUCFsankey
```
#### LULUCF Breakdown Graphs
```{r LULUCF subsectors, warning=FALSE, fig.align = "center", out.width = '95%', fig.cap="Bar graph showing greenhouse gas emissions in megatonnes of CO2 equivalents in the UK's LULUCF sector in 2022 by subsector, stacked by greenhouse gas identity."}
#Bar plot by subsector, stacked by GHG with Plotly
LULUCF_int <- GHG_UK2022 %>%
filter(tes_sector == "LULUCF") %>%
group_by(tes_subsector, ghg, ghg_grouped) %>%
summarize(Temissions = sum(emissions_mt_co2e, na.rm = TRUE)) %>%
pivot_wider(names_from = ghg_grouped, values_from=Temissions) %>%
droplevels() %>%
plot_ly(x = ~tes_subsector, type = 'bar', y = ~CO2, name = 'CO2', marker = list(color ="#3CBD9C")) %>%
add_trace(y = ~CH4, name = 'CH4', marker = list(color ="#C24841")) %>%
add_trace(y = ~N2O, name = 'N2O', marker = list(color ="#D38744")) %>%
layout(yaxis = list(title = 'Emissions/Removals (Mt CO2 eq.)'),
xaxis = list(title = 'Subsector'),
barmode = 'stack'
)
#Plotly customization
style(LULUCF_int, hovertemplate="Subsector: %{x}
%{y:,.4r} Mt CO2 eq.") #define what hover label says, round x values, round y values to 4 sig. figs
```
```{r ag categories, warning=FALSE, fig.align = "center", out.width = '95%', fig.cap="Bar graph showing greenhouse gas emissions in megatonnes of CO2 equivalents in the UK's agriculture sector in 2022 by category, filled by subsector."}
#Bar plot by category, filled by subsector with Plotly
LULUCFcat_int <- GHG_UK2022 %>%
filter(tes_sector == "LULUCF") %>%
group_by(tes_subsector, tes_category) %>%
summarize(Temissions = sum(emissions_mt_co2e, na.rm = TRUE)) %>%
droplevels() %>%
plot_ly(x = ~tes_category, type = 'bar', y = ~Temissions, color = ~tes_subsector,
colors = c("#C24841","#D38744","#96BC61", "#F0C954","#5D7ED1","#3CBD9C", "#F0A7CA"),
marker = list(
width = 1.5
)) %>%
layout(title = 'LULUCF Sources and Sinks by TES Subsector and Category',
yaxis = list(title = 'Emissions/Removals (Mt CO2 eq.)'),
xaxis = list(title = '', tickangle = -90),
legend = list(x = 0.75, y = 0.4, orientation = 'v'),
autosize = F, width = 1000, height = 600,
autoexpand = T,
barmode = 'group'
)
#Plotly customization
style(LULUCFcat_int,
hovertemplate="Category: %{x}
%{y:,.4r} Mt CO2 eq.") #define what hover label says, round x values, round y values to 4 sig. figs
```
```{r LULUCF cat, warning=FALSE, fig.align = "center", out.width = '95%', fig.cap="Bar graph showing greenhouse gas emissions in megatonnes of CO2 equivalents in the UK's LULUCF sector in 2022 by source, stacked by greenhouse gas identity."}
colors <- c(
"#3CBD9C", #transport
"#F0A7CA", #buildings
"#F0C954", #industry
"#C24841", #electricity
"#96BC61", #ag green
"#5D7ED1", #lulucf blue
"#D38744", #fuel
"#A780BB" #waste purple
)
#Bar plot by source with Plotly
LULUCFcat2_int <- GHG_UK2022 %>%
filter(tes_sector == "LULUCF") %>%
group_by(tes_category, ghg) %>%
summarize(Temissions = sum(emissions_mt_co2e, na.rm = TRUE)) %>%
pivot_wider(names_from = ghg, values_from=Temissions) %>%
droplevels() %>%
plot_ly(x = ~tes_category, type = 'bar', y = ~CO2, name = 'CO2', marker = list(color ="#3CBD9C")) %>%
add_trace(y = ~CH4, name = 'CH4', marker = list(color ="#C24841")) %>%
add_trace(y = ~N2O, name = 'N2O', marker = list(color ="#D38744")) %>%
layout(barmode = 'stack',
title = list(text = "LULUCF Sources and Sinks by TES Category and Greenhouse Gas", pad = list(t=50, b=50)),
yaxis = list(title = 'Emissions/Removals (Mt CO2 equivalents)'),
xaxis = list(title = '', tickangle = -90),
autosize = F, width = 1000, height = 600,
autoexpand = T
#legend = list(orientation = "h", title=list(text='<b>Subsector</b>'))
)
#Plotly customization
style(LULUCFcat2_int,
hovertemplate="Source: %{x}
%{y:,.4r} Mt CO2 eq.")
```
```{r, eval=FALSE, include=FALSE, warning=FALSE, fig.align = "center", out.width = '95%', fig.cap="Bar graph showing greenhouse gas emissions in megatonnes of CO2 equivalents in the UK's LULUCF sector in 2022 by source, colored by subsector and grouped by greenhouse gas identity."}
#Plot GHGs into side-by-side plots with Plotly
LULUCF_CO2 <- LULUCFwideGHG %>%
plot_ly(x = ~tes_category, y = ~CO2, color = ~tes_subsector, type = 'bar', legendgroup = ~tes_subsector) %>%
layout(xaxis = list(showticklabels=FALSE, showgrid = FALSE))
LULUCF_CH4 <- LULUCFwideGHG %>%
plot_ly(x = ~tes_category, y = ~CH4, color = ~tes_subsector, type = 'bar', legendgroup = ~tes_subsector, showlegend = F) %>%
layout(xaxis = list(showticklabels=FALSE, showgrid = FALSE))
LULUCF_N2O <- LULUCFwideGHG %>%
plot_ly(x = ~tes_category, y = ~N2O, color = ~tes_subsector, type = 'bar', legendgroup = ~tes_subsector, showlegend = F) %>%
layout(xaxis = list(showticklabels=FALSE, showgrid = FALSE))
LULUCF_GHGs <- subplot(LULUCF_CO2, LULUCF_CH4, LULUCF_N2O, shareY = FALSE, margin = 0.05) %>%
layout(title = list(text = "UK's LULUCF Emissions in 2022", pad = list(t=50, b = 50)),
yaxis = list(title = 'Emissions (Mt CO2 equivalents)'),
plot_bgcolor='#e5ecf6',
legend = list(orientation = "h", title=list(text='<b>Subsector</b>')),
annotations = list(list(
x = 0.125, y = 1.0,
text = "CO2",
xref = "paper",
yref = "paper",
showarrow = FALSE),
list(
x = 0.5, y = 1.0,
text = "CH4",
xref = "paper",
yref = "paper",
showarrow = FALSE),
list(
x = 0.875, y = 1.0,
text = "N2O",
xref = "paper",
yref = "paper",