Initial steps

Add required libraries and tag scenarios to remove from datasets (per plots.py)

suppressMessages(library(tidyverse))
suppressMessages(library(sf))
suppressMessages(library(tmap))
suppressMessages(library(spData))

# Unused scenarios
unused_scenarios <- c("SSP4-3.4-SPA4", "SSP4-6.0-SPA4", "SSP5-3.4-OS")

Mapping countries to regions

Preliminary mapping

From the file country_mapping_ISO-5Regions.csv, select only the three columns relevant per plots.py (adding “Country.Name” to check which countries are mapped where, and for making a map later).

Scroll down for an explanation.

country_mapping <- 
    read.csv("country_mapping_ISO-5Regions.csv") %>% 
    select(c(Country.Name, current.region.defs, NEW.AR6.Ch6.Fig6.4))

country_mapping

region_mapping <- 
    country_mapping %>%
    group_by(current.region.defs, NEW.AR6.Ch6.Fig6.4) %>%
    summarise(count = n()) %>%
    arrange(current.region.defs)
`summarise()` has grouped output by 'current.region.defs'. You can
override using the `.groups` argument.
region_mapping

region_mapping %>% 
    select(!count) %>% 
    summarise(count = n()) %>% 
    arrange(desc(count))

EXPLANATION Above, you can see the 13 “current.region.defs” regions of various countries mapped to 5 different “NEW.AR6.Ch6.Fig6.4” regions. Evidently, there are some overlaps. We explore these in the next section.

Choice of mapping “current.region.defs” to “NEW.AR6.Ch6.Fig6.4”

First we see the breakdown of the number of countries in each of the 5 “NEW.AR6.Ch6.Fig6.4” regions.

Then we look at which countries are resonsible for there being no many-to-one mapping between the old and new region definitions.

country_mapping %>% 
    select(!current.region.defs) %>% 
    group_by(NEW.AR6.Ch6.Fig6.4) %>% 
    summarise(count = n()) %>% 
    arrange(desc(count))

region_EA <- 
    country_mapping %>% 
    filter(current.region.defs == "Eastern Asia")

region_EA %>% 
    filter(NEW.AR6.Ch6.Fig6.4 == "East Asia")

region_EA %>% 
    filter(!NEW.AR6.Ch6.Fig6.4 == "East Asia")

region_NA <- 
    country_mapping %>% 
    filter(current.region.defs == "North America")

region_NA %>% 
    filter(NEW.AR6.Ch6.Fig6.4 == "Central and South America")

region_NA %>% 
    filter(!NEW.AR6.Ch6.Fig6.4 == "Central and South America")

region_SEA_DP <- 
    country_mapping %>% 
    filter(current.region.defs == "South-East Asia and Developing Pacific")

region_SEA_DP %>% 
    filter(NEW.AR6.Ch6.Fig6.4 == "East Asia")

region_SEA_DP %>% 
    filter(!NEW.AR6.Ch6.Fig6.4 == "East Asia")

Regions on the map

Before showing the regions on a map, we first see if the names of the countries match between the two databases. Below you can see that they don’t for several countries (and some regions, such as “French Southern and Antarctic Lands”, which are absent in the IPCC database). For example, “Russian Federation” is “Russia” in the IPCC database, while “eSwatini” is “Swaziland” etc. Nevertheless, the map below shows the distribution of regions.

world_ipcc <- 
    left_join(world, country_mapping, 
              by = join_by(name_long == Country.Name))

world_ipcc %>% 
    select(name_long, NEW.AR6.Ch6.Fig6.4) %>% 
    filter(is.na(NEW.AR6.Ch6.Fig6.4))
Simple feature collection with 18 features and 2 fields
Geometry type: MULTIPOLYGON
Dimension:     XY
Bounding box:  xmin: -180 ymin: -89.9 xmax: 180 ymax: 81.2504
Geodetic CRS:  WGS 84
tm_shape(world_ipcc) + 
    tm_fill(col = "NEW.AR6.Ch6.Fig6.4") + 
    tm_borders()
Some legend labels were too wide. These labels have been resized to 0.48. Increase legend.width (argument of tm_layout) to make the legend wider and therefore the labels larger.

Databases of global and regional emissions

Global emissions

Below you can see the variables from the database, the number of rows (observations), the models used, the scenarios considered and the breakdown of variables.

emissions_global <- 
    read.csv("ar6-wg1-ch6-emissions-global-data.csv") %>% 
    filter(!Scenario %in% unused_scenarios)

cols_global <- colnames(emissions_global)
cols_global
  [1] "Model"    "Scenario" "Region"   "Variable" "Unit"     "X1850"   
  [7] "X1851"    "X1852"    "X1853"    "X1854"    "X1855"    "X1856"   
 [13] "X1857"    "X1858"    "X1859"    "X1860"    "X1861"    "X1862"   
 [19] "X1863"    "X1864"    "X1865"    "X1866"    "X1867"    "X1868"   
 [25] "X1869"    "X1870"    "X1871"    "X1872"    "X1873"    "X1874"   
 [31] "X1875"    "X1876"    "X1877"    "X1878"    "X1879"    "X1880"   
 [37] "X1881"    "X1882"    "X1883"    "X1884"    "X1885"    "X1886"   
 [43] "X1887"    "X1888"    "X1889"    "X1890"    "X1891"    "X1892"   
 [49] "X1893"    "X1894"    "X1895"    "X1896"    "X1897"    "X1898"   
 [55] "X1899"    "X1900"    "X1901"    "X1902"    "X1903"    "X1904"   
 [61] "X1905"    "X1906"    "X1907"    "X1908"    "X1909"    "X1910"   
 [67] "X1911"    "X1912"    "X1913"    "X1914"    "X1915"    "X1916"   
 [73] "X1917"    "X1918"    "X1919"    "X1920"    "X1921"    "X1922"   
 [79] "X1923"    "X1924"    "X1925"    "X1926"    "X1927"    "X1928"   
 [85] "X1929"    "X1930"    "X1931"    "X1932"    "X1933"    "X1934"   
 [91] "X1935"    "X1936"    "X1937"    "X1938"    "X1939"    "X1940"   
 [97] "X1941"    "X1942"    "X1943"    "X1944"    "X1945"    "X1946"   
[103] "X1947"    "X1948"    "X1949"    "X1950"    "X1951"    "X1952"   
[109] "X1953"    "X1954"    "X1955"    "X1956"    "X1957"    "X1958"   
[115] "X1959"    "X1960"    "X1961"    "X1962"    "X1963"    "X1964"   
[121] "X1965"    "X1966"    "X1967"    "X1968"    "X1969"    "X1970"   
[127] "X1971"    "X1972"    "X1973"    "X1974"    "X1975"    "X1976"   
[133] "X1977"    "X1978"    "X1979"    "X1980"    "X1981"    "X1982"   
[139] "X1983"    "X1984"    "X1985"    "X1986"    "X1987"    "X1988"   
[145] "X1989"    "X1990"    "X1991"    "X1992"    "X1993"    "X1994"   
[151] "X1995"    "X1996"    "X1997"    "X1998"    "X1999"    "X2000"   
[157] "X2001"    "X2002"    "X2003"    "X2004"    "X2005"    "X2006"   
[163] "X2007"    "X2008"    "X2009"    "X2010"    "X2011"    "X2012"   
[169] "X2013"    "X2014"    "X2015"    "X2016"    "X2017"    "X2018"   
[175] "X2019"    "X2020"    "X2030"    "X2040"    "X2050"    "X2060"   
[181] "X2070"    "X2080"    "X2090"    "X2100"   
nrow(emissions_global)
[1] 807
unique(emissions_global$Model)
 [1] "AIM/CGE"         "CMIP5"           "CMIP6"          
 [4] "EDGAR"           "Ev5a"            "GAINS"          
 [7] "History"         "IMAGE"           "MESSAGE-GLOBIOM"
[10] "RCP"             "REMIND-MAGPIE"  
unique(emissions_global$Scenario)
 [1] "SSP3-7.0-SPA0"       "SSP3-LowNTCF"        "History"            
 [4] "CLE"                 "MTFR"                "SLCF"               
 [7] "GAINS-CLE"           "GAINS-KA"            "GAINS-MTFR"         
[10] "Velders-(2015) high" "Velders-(2015) low"  "ECLIPSE_Ev5a"       
[13] "EDGAR"               "SSP1-1.9-SPA1"       "SSP1-2.6-SPA1"      
[16] "SSP2-4.5-SPA2"       "RCP 2.6"             "RCP 4.5"            
[19] "RCP 6.0"             "RCP 8.5"             "RCP3-PD(2.6)"       
[22] "RCP4.5"              "RCP6.0"              "RCP8.5"             
[25] "SSP5-8.5"           
unique(emissions_global$Region)
[1] "World"
unique(emissions_global$Variable)
  [1] "Emissions|BC"                                     
  [2] "Emissions|BC|Agricultural Waste Burning"          
  [3] "Emissions|BC|Aircraft"                            
  [4] "Emissions|BC|Energy Sector"                       
  [5] "Emissions|BC|Forest Burning"                      
  [6] "Emissions|BC|Grassland Burning"                   
  [7] "Emissions|BC|Industrial Sector"                   
  [8] "Emissions|BC|International Shipping"              
  [9] "Emissions|BC|Peat Burning"                        
 [10] "Emissions|BC|Residential Commercial Other"        
 [11] "Emissions|BC|Transportation Sector"               
 [12] "Emissions|BC|Waste"                               
 [13] "Emissions|C2F6"                                   
 [14] "Emissions|CF4"                                    
 [15] "Emissions|CH4"                                    
 [16] "Emissions|CH4|Agricultural Waste Burning"         
 [17] "Emissions|CH4|Agriculture"                        
 [18] "Emissions|CH4|Energy Sector"                      
 [19] "Emissions|CH4|Forest Burning"                     
 [20] "Emissions|CH4|Grassland Burning"                  
 [21] "Emissions|CH4|Industrial Sector"                  
 [22] "Emissions|CH4|International Shipping"             
 [23] "Emissions|CH4|Peat Burning"                       
 [24] "Emissions|CH4|Residential Commercial Other"       
 [25] "Emissions|CH4|Transportation Sector"              
 [26] "Emissions|CH4|Waste"                              
 [27] "Emissions|CO"                                     
 [28] "Emissions|CO2"                                    
 [29] "Emissions|CO2|AFOLU"                              
 [30] "Emissions|CO2|Aircraft"                           
 [31] "Emissions|CO2|Energy Sector"                      
 [32] "Emissions|CO2|Industrial Sector"                  
 [33] "Emissions|CO2|International Shipping"             
 [34] "Emissions|CO2|Residential Commercial Other"       
 [35] "Emissions|CO2|Solvents Production and Application"
 [36] "Emissions|CO2|Transportation Sector"              
 [37] "Emissions|CO2|Waste"                              
 [38] "Emissions|CO|Agricultural Waste Burning"          
 [39] "Emissions|CO|Aircraft"                            
 [40] "Emissions|CO|Energy Sector"                       
 [41] "Emissions|CO|Forest Burning"                      
 [42] "Emissions|CO|Grassland Burning"                   
 [43] "Emissions|CO|Industrial Sector"                   
 [44] "Emissions|CO|International Shipping"              
 [45] "Emissions|CO|Peat Burning"                        
 [46] "Emissions|CO|Residential Commercial Other"        
 [47] "Emissions|CO|Transportation Sector"               
 [48] "Emissions|CO|Waste"                               
 [49] "Emissions|HFC"                                    
 [50] "Emissions|N2O"                                    
 [51] "Emissions|NH3"                                    
 [52] "Emissions|NH3|Agricultural Waste Burning"         
 [53] "Emissions|NH3|Agriculture"                        
 [54] "Emissions|NH3|Aircraft"                           
 [55] "Emissions|NH3|Energy Sector"                      
 [56] "Emissions|NH3|Forest Burning"                     
 [57] "Emissions|NH3|Grassland Burning"                  
 [58] "Emissions|NH3|Industrial Sector"                  
 [59] "Emissions|NH3|International Shipping"             
 [60] "Emissions|NH3|Peat Burning"                       
 [61] "Emissions|NH3|Residential Commercial Other"       
 [62] "Emissions|NH3|Transportation Sector"              
 [63] "Emissions|NH3|Waste"                              
 [64] "Emissions|NOx"                                    
 [65] "Emissions|NOx|Agricultural Waste Burning"         
 [66] "Emissions|NOx|Agriculture"                        
 [67] "Emissions|NOx|Aircraft"                           
 [68] "Emissions|NOx|Energy Sector"                      
 [69] "Emissions|NOx|Forest Burning"                     
 [70] "Emissions|NOx|Grassland Burning"                  
 [71] "Emissions|NOx|Industrial Sector"                  
 [72] "Emissions|NOx|International Shipping"             
 [73] "Emissions|NOx|Peat Burning"                       
 [74] "Emissions|NOx|Residential Commercial Other"       
 [75] "Emissions|NOx|Transportation Sector"              
 [76] "Emissions|NOx|Waste"                              
 [77] "Emissions|OC"                                     
 [78] "Emissions|OC|Agricultural Waste Burning"          
 [79] "Emissions|OC|Aircraft"                            
 [80] "Emissions|OC|Energy Sector"                       
 [81] "Emissions|OC|Forest Burning"                      
 [82] "Emissions|OC|Grassland Burning"                   
 [83] "Emissions|OC|Industrial Sector"                   
 [84] "Emissions|OC|International Shipping"              
 [85] "Emissions|OC|Peat Burning"                        
 [86] "Emissions|OC|Residential Commercial Other"        
 [87] "Emissions|OC|Transportation Sector"               
 [88] "Emissions|OC|Waste"                               
 [89] "Emissions|SF6"                                    
 [90] "Emissions|Sulfur"                                 
 [91] "Emissions|Sulfur|Agricultural Waste Burning"      
 [92] "Emissions|Sulfur|Aircraft"                        
 [93] "Emissions|Sulfur|Energy Sector"                   
 [94] "Emissions|Sulfur|Forest Burning"                  
 [95] "Emissions|Sulfur|Grassland Burning"               
 [96] "Emissions|Sulfur|Industrial Sector"               
 [97] "Emissions|Sulfur|International Shipping"          
 [98] "Emissions|Sulfur|Peat Burning"                    
 [99] "Emissions|Sulfur|Residential Commercial Other"    
[100] "Emissions|Sulfur|Transportation Sector"           
[101] "Emissions|Sulfur|Waste"                           
[102] "Emissions|VOC"                                    
[103] "Emissions|VOC|Agricultural Waste Burning"         
[104] "Emissions|VOC|Aircraft"                           
[105] "Emissions|VOC|Energy Sector"                      
[106] "Emissions|VOC|Forest Burning"                     
[107] "Emissions|VOC|Grassland Burning"                  
[108] "Emissions|VOC|Industrial Sector"                  
[109] "Emissions|VOC|International Shipping"             
[110] "Emissions|VOC|Peat Burning"                       
[111] "Emissions|VOC|Residential Commercial Other"       
[112] "Emissions|VOC|Solvents Production and Application"
[113] "Emissions|VOC|Transportation Sector"              
[114] "Emissions|VOC|Waste"                              
[115] "Emissions|PFC"                                    

Regional emissions

The same information as above is shown here, but for regional emissions from the file ar6-wg1-ch6-emissions-regional-data-5regions.csv.

# N.B.: Uses five regions
emissions_regional <- 
    read.csv("ar6-wg1-ch6-emissions-regional-data-5regions.csv") %>% 
    filter(!Scenario %in% unused_scenarios)

cols_regional <- colnames(emissions_regional)
cols_regional
  [1] "Model"    "Scenario" "Region"   "Variable" "Unit"     "X1850"   
  [7] "X1851"    "X1852"    "X1853"    "X1854"    "X1855"    "X1856"   
 [13] "X1857"    "X1858"    "X1859"    "X1860"    "X1861"    "X1862"   
 [19] "X1863"    "X1864"    "X1865"    "X1866"    "X1867"    "X1868"   
 [25] "X1869"    "X1870"    "X1871"    "X1872"    "X1873"    "X1874"   
 [31] "X1875"    "X1876"    "X1877"    "X1878"    "X1879"    "X1880"   
 [37] "X1881"    "X1882"    "X1883"    "X1884"    "X1885"    "X1886"   
 [43] "X1887"    "X1888"    "X1889"    "X1890"    "X1891"    "X1892"   
 [49] "X1893"    "X1894"    "X1895"    "X1896"    "X1897"    "X1898"   
 [55] "X1899"    "X1900"    "X1901"    "X1902"    "X1903"    "X1904"   
 [61] "X1905"    "X1906"    "X1907"    "X1908"    "X1909"    "X1910"   
 [67] "X1911"    "X1912"    "X1913"    "X1914"    "X1915"    "X1916"   
 [73] "X1917"    "X1918"    "X1919"    "X1920"    "X1921"    "X1922"   
 [79] "X1923"    "X1924"    "X1925"    "X1926"    "X1927"    "X1928"   
 [85] "X1929"    "X1930"    "X1931"    "X1932"    "X1933"    "X1934"   
 [91] "X1935"    "X1936"    "X1937"    "X1938"    "X1939"    "X1940"   
 [97] "X1941"    "X1942"    "X1943"    "X1944"    "X1945"    "X1946"   
[103] "X1947"    "X1948"    "X1949"    "X1950"    "X1951"    "X1952"   
[109] "X1953"    "X1954"    "X1955"    "X1956"    "X1957"    "X1958"   
[115] "X1959"    "X1960"    "X1961"    "X1962"    "X1963"    "X1964"   
[121] "X1965"    "X1966"    "X1967"    "X1968"    "X1969"    "X1970"   
[127] "X1971"    "X1972"    "X1973"    "X1974"    "X1975"    "X1976"   
[133] "X1977"    "X1978"    "X1979"    "X1980"    "X1981"    "X1982"   
[139] "X1983"    "X1984"    "X1985"    "X1986"    "X1987"    "X1988"   
[145] "X1989"    "X1990"    "X1991"    "X1992"    "X1993"    "X1994"   
[151] "X1995"    "X1996"    "X1997"    "X1998"    "X1999"    "X2000"   
[157] "X2001"    "X2002"    "X2003"    "X2004"    "X2005"    "X2006"   
[163] "X2007"    "X2008"    "X2009"    "X2010"    "X2011"    "X2012"   
[169] "X2013"    "X2014"    "X2015"    "X2020"    "X2030"    "X2040"   
[175] "X2050"    "X2060"    "X2070"    "X2080"    "X2090"    "X2100"   
nrow(emissions_regional)
[1] 4565
unique(emissions_regional$Model)
[1] "AIM"             "CMIP5"           "CMIP6"           "History"        
[5] "IMAGE"           "MESSAGE-GLOBIOM" "RCP"             "REMIND-MAGPIE"  
unique(emissions_regional$Scenario)
 [1] "SSP3-7.0-SPA0" "SSP3-LowNTCF"  "History"       "CEDS"         
 [5] "SSP1-1.9-SPA1" "SSP1-2.6-SPA1" "SSP2-4.5-SPA2" "RCP 2.6"      
 [9] "RCP 4.5"       "RCP 6.0"       "RCP 8.5"       "SSP5-8.5"     
unique(emissions_regional$Region)
[1] "Africa and Middle East"                                       
[2] "Central and South America"                                    
[3] "East Asia"                                                    
[4] "North America, Europe, Russia, Central Asia, and Pacific OECD"
[5] "South and South East Asia, Other Pacific"                     
unique(emissions_regional$Variable)
  [1] "Emissions|BC"                                        
  [2] "Emissions|BC|Agricultural Waste Burning"             
  [3] "Emissions|BC|Agriculture"                            
  [4] "Emissions|BC|Energy Sector"                          
  [5] "Emissions|BC|Forest Burning"                         
  [6] "Emissions|BC|Grassland Burning"                      
  [7] "Emissions|BC|Industrial Sector"                      
  [8] "Emissions|BC|Peat Burning"                           
  [9] "Emissions|BC|Residential Commercial Other"           
 [10] "Emissions|BC|Solvents Production and Application"    
 [11] "Emissions|BC|Transportation Sector"                  
 [12] "Emissions|BC|Waste"                                  
 [13] "Emissions|CH4"                                       
 [14] "Emissions|CH4|Agricultural Waste Burning"            
 [15] "Emissions|CH4|Agriculture"                           
 [16] "Emissions|CH4|Energy Sector"                         
 [17] "Emissions|CH4|Forest Burning"                        
 [18] "Emissions|CH4|Grassland Burning"                     
 [19] "Emissions|CH4|Industrial Sector"                     
 [20] "Emissions|CH4|Peat Burning"                          
 [21] "Emissions|CH4|Residential Commercial Other"          
 [22] "Emissions|CH4|Solvents Production and Application"   
 [23] "Emissions|CH4|Transportation Sector"                 
 [24] "Emissions|CH4|Waste"                                 
 [25] "Emissions|CO"                                        
 [26] "Emissions|CO2"                                       
 [27] "Emissions|CO2|Agricultural Waste Burning"            
 [28] "Emissions|CO2|Agriculture"                           
 [29] "Emissions|CO2|Energy Sector"                         
 [30] "Emissions|CO2|Forest Burning"                        
 [31] "Emissions|CO2|Grassland Burning"                     
 [32] "Emissions|CO2|Industrial Sector"                     
 [33] "Emissions|CO2|Peat Burning"                          
 [34] "Emissions|CO2|Residential Commercial Other"          
 [35] "Emissions|CO2|Solvents Production and Application"   
 [36] "Emissions|CO2|Transportation Sector"                 
 [37] "Emissions|CO2|Waste"                                 
 [38] "Emissions|CO|Agricultural Waste Burning"             
 [39] "Emissions|CO|Agriculture"                            
 [40] "Emissions|CO|Energy Sector"                          
 [41] "Emissions|CO|Forest Burning"                         
 [42] "Emissions|CO|Grassland Burning"                      
 [43] "Emissions|CO|Industrial Sector"                      
 [44] "Emissions|CO|Peat Burning"                           
 [45] "Emissions|CO|Residential Commercial Other"           
 [46] "Emissions|CO|Solvents Production and Application"    
 [47] "Emissions|CO|Transportation Sector"                  
 [48] "Emissions|CO|Waste"                                  
 [49] "Emissions|NH3"                                       
 [50] "Emissions|NH3|Agricultural Waste Burning"            
 [51] "Emissions|NH3|Agriculture"                           
 [52] "Emissions|NH3|Energy Sector"                         
 [53] "Emissions|NH3|Forest Burning"                        
 [54] "Emissions|NH3|Grassland Burning"                     
 [55] "Emissions|NH3|Industrial Sector"                     
 [56] "Emissions|NH3|Peat Burning"                          
 [57] "Emissions|NH3|Residential Commercial Other"          
 [58] "Emissions|NH3|Solvents Production and Application"   
 [59] "Emissions|NH3|Transportation Sector"                 
 [60] "Emissions|NH3|Waste"                                 
 [61] "Emissions|NMVOC|Agricultural Waste Burning"          
 [62] "Emissions|NMVOC|Agriculture"                         
 [63] "Emissions|NMVOC|Energy Sector"                       
 [64] "Emissions|NMVOC|Forest Burning"                      
 [65] "Emissions|NMVOC|Grassland Burning"                   
 [66] "Emissions|NMVOC|Industrial Sector"                   
 [67] "Emissions|NMVOC|Peat Burning"                        
 [68] "Emissions|NMVOC|Residential Commercial Other"        
 [69] "Emissions|NMVOC|Solvents Production and Application" 
 [70] "Emissions|NMVOC|Transportation Sector"               
 [71] "Emissions|NMVOC|Waste"                               
 [72] "Emissions|NOx"                                       
 [73] "Emissions|NOx|Agricultural Waste Burning"            
 [74] "Emissions|NOx|Agriculture"                           
 [75] "Emissions|NOx|Energy Sector"                         
 [76] "Emissions|NOx|Forest Burning"                        
 [77] "Emissions|NOx|Grassland Burning"                     
 [78] "Emissions|NOx|Industrial Sector"                     
 [79] "Emissions|NOx|Peat Burning"                          
 [80] "Emissions|NOx|Residential Commercial Other"          
 [81] "Emissions|NOx|Solvents Production and Application"   
 [82] "Emissions|NOx|Transportation Sector"                 
 [83] "Emissions|NOx|Waste"                                 
 [84] "Emissions|OC"                                        
 [85] "Emissions|OC|Agricultural Waste Burning"             
 [86] "Emissions|OC|Agriculture"                            
 [87] "Emissions|OC|Energy Sector"                          
 [88] "Emissions|OC|Forest Burning"                         
 [89] "Emissions|OC|Grassland Burning"                      
 [90] "Emissions|OC|Industrial Sector"                      
 [91] "Emissions|OC|Peat Burning"                           
 [92] "Emissions|OC|Residential Commercial Other"           
 [93] "Emissions|OC|Solvents Production and Application"    
 [94] "Emissions|OC|Transportation Sector"                  
 [95] "Emissions|OC|Waste"                                  
 [96] "Emissions|Sulfur"                                    
 [97] "Emissions|Sulfur|Agricultural Waste Burning"         
 [98] "Emissions|Sulfur|Agriculture"                        
 [99] "Emissions|Sulfur|Energy Sector"                      
[100] "Emissions|Sulfur|Forest Burning"                     
[101] "Emissions|Sulfur|Grassland Burning"                  
[102] "Emissions|Sulfur|Industrial Sector"                  
[103] "Emissions|Sulfur|Peat Burning"                       
[104] "Emissions|Sulfur|Residential Commercial Other"       
[105] "Emissions|Sulfur|Solvents Production and Application"
[106] "Emissions|Sulfur|Transportation Sector"              
[107] "Emissions|Sulfur|Waste"                              
[108] "Emissions|VOC"                                       
[109] "Emissions|VOC|Agricultural Waste Burning"            
[110] "Emissions|VOC|Agriculture"                           
[111] "Emissions|VOC|Energy Sector"                         
[112] "Emissions|VOC|Forest Burning"                        
[113] "Emissions|VOC|Grassland Burning"                     
[114] "Emissions|VOC|Industrial Sector"                     
[115] "Emissions|VOC|Peat Burning"                          
[116] "Emissions|VOC|Residential Commercial Other"          
[117] "Emissions|VOC|Solvents Production and Application"   
[118] "Emissions|VOC|Transportation Sector"                 
[119] "Emissions|VOC|Waste"                                 
[120] "Emissions|N2O"                                       
[121] "Emissions|PFC"                                       
[122] "Emissions|SF6"                                       

Comparing global and regional databases

While the database of global emissions has 184 variables, that for regional emissions only has 180. Below we see which variables are missing from the latter.

janitor::compare_df_cols(emissions_global, emissions_regional) %>% 
    filter(is.na(emissions_regional))

Comparing two CSV files of regional data

The IPCC has provided two seemingly identical databases with different names: ar6-wg1-ch6-emissions-regional-data-5regions.csv and ar6-wg1-ch6-emissions-regional-data.csv. Initially, it seemed like the latter had more granular information about the regions (perhaps mapped to “current.region.defs”), but this is not the case: it has the same region names as the other file. Further exploration shows some differences between the two files, as shown below.

emissions_current_regions <- 
    read.csv("ar6-wg1-ch6-emissions-regional-data.csv") %>% 
    filter(!Scenario %in% unused_scenarios) 
# %>% 
#   rename(Current_Region = Region)

unique(emissions_current_regions$Region)
[1] "Africa and Middle East"                                       
[2] "Central and South America"                                    
[3] "East Asia"                                                    
[4] "North America, Europe, Russia, Central Asia, and Pacific OECD"
[5] "South and South East Asia, Other Pacific"                     
summary(arsenal::comparedf(emissions_current_regions, emissions_regional))
Summary of data.frames
version arg ncol nrow
x emissions_current_regions 180 4565
y emissions_regional 180 4565
NA
Summary of overall comparison
statistic value
Number of by-variables 0
Number of non-by variables in common 180
Number of variables compared 180
Number of variables in x but not y 0
Number of variables in y but not x 0
Number of variables compared with some values unequal 175
Number of variables compared with all values equal 5
Number of observations in common 4565
Number of observations in x but not y 0
Number of observations in y but not x 0
Number of observations with some compared variables unequal 2272
Number of observations with all compared variables equal 2293
Number of values unequal 29518
NA
Variables not shared
No variables not shared
NA
Other variables not compared
No other variables not compared
NA
Observations not shared
No observations not shared
NA
Differences detected by variable
var.x var.y n NAs
Model Model 0 0
Scenario Scenario 0 0
Region Region 0 0
Variable Variable 0 0
Unit Unit 0 0
X1850 X1850 30 0
X1851 X1851 28 0
X1852 X1852 28 0
X1853 X1853 28 0
X1854 X1854 28 0
X1855 X1855 28 0
X1856 X1856 28 0
X1857 X1857 28 0
X1858 X1858 28 0
X1859 X1859 28 0
X1860 X1860 30 0
X1861 X1861 28 0
X1862 X1862 28 0
X1863 X1863 28 0
X1864 X1864 28 0
X1865 X1865 28 0
X1866 X1866 28 0
X1867 X1867 28 0
X1868 X1868 28 0
X1869 X1869 28 0
X1870 X1870 30 0
X1871 X1871 28 0
X1872 X1872 28 0
X1873 X1873 28 0
X1874 X1874 28 0
X1875 X1875 28 0
X1876 X1876 28 0
X1877 X1877 28 0
X1878 X1878 28 0
X1879 X1879 28 0
X1880 X1880 30 0
X1881 X1881 28 0
X1882 X1882 28 0
X1883 X1883 28 0
X1884 X1884 28 0
X1885 X1885 28 0
X1886 X1886 28 0
X1887 X1887 28 0
X1888 X1888 28 0
X1889 X1889 28 0
X1890 X1890 30 0
X1891 X1891 28 0
X1892 X1892 28 0
X1893 X1893 28 0
X1894 X1894 28 0
X1895 X1895 28 0
X1896 X1896 28 0
X1897 X1897 28 0
X1898 X1898 28 0
X1899 X1899 28 0
X1900 X1900 30 0
X1901 X1901 28 0
X1902 X1902 28 0
X1903 X1903 28 0
X1904 X1904 28 0
X1905 X1905 28 0
X1906 X1906 28 0
X1907 X1907 28 0
X1908 X1908 28 0
X1909 X1909 28 0
X1910 X1910 30 0
X1911 X1911 28 0
X1912 X1912 28 0
X1913 X1913 28 0
X1914 X1914 28 0
X1915 X1915 28 0
X1916 X1916 28 0
X1917 X1917 28 0
X1918 X1918 28 0
X1919 X1919 28 0
X1920 X1920 30 0
X1921 X1921 28 0
X1922 X1922 28 0
X1923 X1923 28 0
X1924 X1924 28 0
X1925 X1925 28 0
X1926 X1926 28 0
X1927 X1927 28 0
X1928 X1928 28 0
X1929 X1929 28 0
X1930 X1930 30 0
X1931 X1931 28 0
X1932 X1932 28 0
X1933 X1933 28 0
X1934 X1934 28 0
X1935 X1935 28 0
X1936 X1936 28 0
X1937 X1937 28 0
X1938 X1938 28 0
X1939 X1939 28 0
X1940 X1940 30 0
X1941 X1941 28 0
X1942 X1942 28 0
X1943 X1943 28 0
X1944 X1944 28 0
X1945 X1945 28 0
X1946 X1946 28 0
X1947 X1947 28 0
X1948 X1948 28 0
X1949 X1949 28 0
X1950 X1950 30 0
X1951 X1951 28 0
X1952 X1952 28 0
X1953 X1953 28 0
X1954 X1954 28 0
X1955 X1955 28 0
X1956 X1956 28 0
X1957 X1957 28 0
X1958 X1958 28 0
X1959 X1959 28 0
X1960 X1960 30 0
X1961 X1961 28 0
X1962 X1962 28 0
X1963 X1963 28 0
X1964 X1964 28 0
X1965 X1965 28 0
X1966 X1966 28 0
X1967 X1967 28 0
X1968 X1968 28 0
X1969 X1969 28 0
X1970 X1970 32 0
X1971 X1971 32 0
X1972 X1972 32 0
X1973 X1973 32 0
X1974 X1974 32 0
X1975 X1975 32 0
X1976 X1976 32 0
X1977 X1977 32 0
X1978 X1978 32 0
X1979 X1979 32 0
X1980 X1980 32 0
X1981 X1981 32 0
X1982 X1982 32 0
X1983 X1983 32 0
X1984 X1984 32 0
X1985 X1985 32 0
X1986 X1986 32 0
X1987 X1987 32 0
X1988 X1988 32 0
X1989 X1989 32 0
X1990 X1990 316 0
X1991 X1991 316 0
X1992 X1992 316 0
X1993 X1993 316 0
X1994 X1994 316 0
X1995 X1995 316 0
X1996 X1996 316 0
X1997 X1997 316 0
X1998 X1998 316 0
X1999 X1999 316 0
X2000 X2000 316 0
X2001 X2001 316 0
X2002 X2002 316 0
X2003 X2003 316 0
X2004 X2004 316 0
X2005 X2005 316 0
X2006 X2006 316 0
X2007 X2007 316 0
X2008 X2008 316 0
X2009 X2009 316 0
X2010 X2010 316 0
X2011 X2011 316 0
X2012 X2012 316 0
X2013 X2013 316 0
X2014 X2014 316 0
X2015 X2015 2272 0
X2020 X2020 1704 0
X2030 X2030 1704 0
X2040 X2040 1704 0
X2050 X2050 1704 0
X2060 X2060 1704 0
X2070 X2070 1704 0
X2080 X2080 1702 0
X2090 X2090 1702 0
X2100 X2100 1694 0
NA
Differences detected (29468 not shown)
var.x var.y ..row.names.. values.x values.y row.x row.y
X1850 X1850 1229 0.1505004 0.1504872 1229 1229
X1850 X1850 1253 22.50398 22.50319 1253 1253
X1850 X1850 1277 0.5179229 0.5176253 1277 1277
X1850 X1850 1300 0.9042424 0.9042411 1300 1300
X1850 X1850 1312 1.046345 1.046293 1312 1312
X1850 X1850 1324 0.1680475 0.1680454 1324 1324
X1850 X1850 1336 4.115626 4.115514 1336 1336
X1850 X1850 1337 0.4094407 0.3228789 1337 1337
X1850 X1850 1349 5.189415 4.260081 1349 1349
X1850 X1850 1361 53.58271 38.89107 1361 1361
X1851 X1851 1229 0.1501614 0.1501485 1229 1229
X1851 X1851 1253 22.42899 22.42821 1253 1253
X1851 X1851 1277 0.5197037 0.5194107 1277 1277
X1851 X1851 1300 0.9009933 0.900992 1300 1300
X1851 X1851 1312 1.043122 1.043071 1312 1312
X1851 X1851 1324 0.1691642 0.1691622 1324 1324
X1851 X1851 1336 4.100179 4.100069 1336 1336
X1851 X1851 1337 0.4064968 0.3199004 1337 1337
X1851 X1851 1361 53.18587 38.49895 1361 1361
X1851 X1851 1385 2.256342 2.04618 1385 1385
X1852 X1852 1229 0.149141 0.1491282 1229 1229
X1852 X1852 1253 22.22951 22.22874 1253 1253
X1852 X1852 1277 0.5200344 0.5197443 1277 1277
X1852 X1852 1300 0.8920096 0.8920084 1300 1300
X1852 X1852 1312 1.034633 1.034582 1312 1312
X1852 X1852 1324 0.1695278 0.1695258 1324 1324
X1852 X1852 1336 4.059667 4.059557 1336 1336
X1852 X1852 1337 0.402734 0.3172693 1337 1337
X1852 X1852 1361 52.6472 38.16506 1361 1361
X1852 X1852 1385 2.240239 2.032107 1385 1385
X1853 X1853 1229 0.1494289 0.1494161 1229 1229
X1853 X1853 1253 22.24423 22.24346 1253 1253
X1853 X1853 1277 0.523373 0.5230808 1277 1277
X1853 X1853 1300 0.8918505 0.8918492 1300 1300
X1853 X1853 1312 1.036115 1.036064 1312 1312
X1853 X1853 1324 0.1712046 0.1712026 1324 1324
X1853 X1853 1336 4.059909 4.059798 1336 1336
X1853 X1853 1337 0.4006968 0.315039 1337 1337
X1853 X1853 1361 52.4047 37.90016 1361 1361
X1853 X1853 1385 2.227885 2.01911 1385 1385
X1854 X1854 1229 0.1501585 0.1501456 1229 1229
X1854 X1854 1253 22.33223 22.33145 1253 1253
X1854 X1854 1277 0.5276405 0.5273462 1277 1277
X1854 X1854 1300 0.894728 0.8947267 1300 1300
X1854 X1854 1312 1.041123 1.041072 1312 1312
X1854 X1854 1324 0.1733496 0.1733476 1324 1324
X1854 X1854 1336 4.074119 4.074007 1336 1336
X1854 X1854 1337 0.3980772 0.3126279 1337 1337
X1854 X1854 1361 52.06323 37.60535 1361 1361
X1854 X1854 1385 2.214194 2.005584 1385 1385
NA
Non-identical attributes
No non-identical attributes
NA

Comparing emission types

Based on the below graph (and the ones in the sections below), it appears that the emissions recorded by just the name of the chemical are the aggregate value of the individual contributing factors.

emissions_regional %>% 
    filter(grepl("CH4", Variable)) %>% 
    filter(Region == "Africa and Middle East") %>% 
    filter(Model == "AIM") %>% 
    filter(grepl("LowNTCF", Scenario)) %>% 
    select(!Model) %>% 
    select(!Scenario) %>% 
    select(!Region) %>% 
    select(!Unit) %>% 
    rename_with(~ str_remove(., "X"), everything()) %>% 
    pivot_longer(
        cols = "1850":"2100",
        names_to = "year",
        values_to = "count"
    ) %>% 
    mutate(year = as.Date(year, format = "%Y")) %>% 
    mutate(year = as.numeric(format(year, "%Y"))) %>% 
    filter(year >= 2020) %>% 
    #select(!year) %>% 
    ggplot() + 
    geom_col(aes(count, fct_reorder(Variable, count))) + 
    facet_grid(cols = vars(year))

Reproduction of graphics

First we look at methane emissions in Africa and the Middle East, to compare with the top-left plot from the original figure.

emissions_regional %>% 
    filter(Variable == "Emissions|CH4") %>% 
    select(!Variable) %>% 
    filter(Region == "Africa and Middle East") %>% 
    select(!Region) %>% 
    select(!Unit) %>%  
    unite(Model_Scenario, c("Model", "Scenario")) %>% 
    rename_with(~ str_remove(., "X"), everything()) %>% 
    pivot_longer(
        cols = "1850":"2100",
        names_to = "year",
        values_to = "count"
    ) %>% 
    mutate(year = as.Date(year, format = "%Y")) %>% 
    mutate(year = as.numeric(format(year, "%Y"))) %>%
    ggplot() +
    geom_point(aes(x = year, y = count, colour = Model_Scenario)) +
    geom_line(aes(x = year, y = count, colour = Model_Scenario)) 

Then we look at the RCP-only data, which matches with the grey area in the original figure. It appears that for each year, the minimum and maximum of all four datasets is used to plot the boundaries of the grey area.

emissions_regional %>% 
    filter(Variable == "Emissions|CH4") %>% 
    select(!Variable) %>% 
    filter(Region == "Africa and Middle East") %>% 
    select(!Region) %>% 
    select(!Unit) %>%  
    unite(Model_Scenario, c("Model", "Scenario")) %>% 
    rename_with(~ str_remove(., "X"), everything()) %>% 
    pivot_longer(
        cols = "1850":"2100",
        names_to = "year",
        values_to = "count"
    ) %>% 
    filter(grepl("RCP", Model_Scenario)) %>% 
    mutate(year = as.Date(year, format = "%Y")) %>% 
    mutate(year = as.numeric(format(year, "%Y"))) %>%
    ggplot() +
    geom_point(aes(x = year, y = count, colour = Model_Scenario)) +
    geom_line(aes(x = year, y = count, colour = Model_Scenario)) 

Below is the faceted breakdown of all emissions by region. N.B.: Where the original plot shows data for “NMVOC”, it comes from the value of ”Emissions|VOC” in the dataset. Also note that I cannot get the order of the gases to match the original plot (yet). The labelling also needs some work, but the plotting itself seems to be OK.

emissions_type <- c("Emissions|CH4"
                  , "Emissions|BC"
                  , "Emissions|Sulfur"
                  , "Emissions|CO"
                  , "Emissions|NH3"
                  , "Emissions|VOC"
                  , "Emissions|NOx"
                  , "Emissions|OC"
                    )

emissions_regional %>% 
    filter(Variable %in% emissions_type) %>% 
    mutate(Variable = as.factor(Variable)) %>% 
    select(!Unit) %>%  
    unite(Model_Scenario, c("Model", "Scenario")) %>% 
    rename_with(~ str_remove(., "X"), everything()) %>% 
    pivot_longer(
        cols = "1850":"2100",
        names_to = "year",
        values_to = "count"
    ) %>% 
    mutate(year = as.Date(year, format = "%Y")) %>% 
    mutate(year = as.numeric(format(year, "%Y"))) %>%
    ggplot() +
    geom_point(aes(x = year, y = count, colour = Model_Scenario)) +
    geom_line(aes(x = year, y = count, colour = Model_Scenario)) +
    facet_grid(rows = vars(Variable), cols = vars(Region), scales = "free_y")



# mutate(Variable = fct_relevel(Variable),
#          levels = c("Emissions|CH4"
#                   , "Emissions|BC"
#                   , "Emissions|OC"
#                   , "Emissions|Sulfur"
#                   , "Emissions|NOx"
#                   , "Emissions|CO"
#                   , "Emissions|VOC"
#                   , "Emissions|NH3"
#                   ))
    
LS0tCnRpdGxlOiAiSVBDQyBBUjYgV0cxIENoLjYgRmlnLjE5IgpvdXRwdXQ6IGh0bWxfbm90ZWJvb2sKZWRpdG9yX29wdGlvbnM6IAogIGNodW5rX291dHB1dF90eXBlOiBpbmxpb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