17 June 2017

New Zealand greenhouse gases by sector from the inventory

I have made another chart from the New Zealand's Greenhouse Gas Inventory 1990–2015 released the other week by the Ministry for the Environment.

It shows the greenhouse gas emissions by sectors of the economy. It includes 'negative' emissions, more properly called carbon removals, or carbon sequestration or simply carbon sinks. This is the sum of all the carbon dioxide taken out of the atmosphere by the sector of the economy called Land use, Land use change and Forestry.

Here is the chart.

This time I took a more traditional R approach to getting the the data into R from the Excel file CRF summary data.xlsx.

First, I used opened an X terminal window, and used the Linux wget command to download the spreadsheet "2017 CRF Summary data.xlsx" to a folder called "/nzghg2015".

I then used ssconvert (which is part of Gnumeric) to split the Excel (.xlsx) spreadsheet into comma-separated values files.

# open an XFCE terminal window, change directory, use the wget command to download "2017%20CRF%20Summary%20data.xlsx" to /nzghg2015 folder
$ cd /home/user/R/nzghg2015/
$ wget http://www.mfe.govt.nz/sites/default/files/media/2017%20CRF%20Summary%20data.xlsx
# use Gnumeric via the command line to convert the .xlsx file and it's work sheets to separate .csv files with sheet number appended in place of "%n" and the most recent year of emissions (not the year of publication)
$ ssconvert -S --export-file-per-sheet '2017 CRF Summary data.xlsx' crf-data-2015-%n.csv
# list contents of folder to see the two new csv data files
$ ls -l
total 180
-rw-r--r-- 1 user user 46759 May 23 10:49 2017 CRF Summary data.xlsx
-rw-r--r-- 1 user user 3749 Jun 14 14:26 crf-data-2015-0.csv
-rw-r--r-- 1 user user 5425 Jun 14 14:26 crf-data-2015-1.csv
-rw-r--r-- 1 user user 1 Jun 14 14:26 crf-data-2015-2.csv

The Excel spreadsheet had 3 work sheets, 2 with data, and 1 that was empty. So there's now a .csv file for each sheet, even the empty sheet. And we read in the .csv file for emissions by sector.

# to read the .csv data file of GHG emissions by sector to the R workspace as a dataframe
gsector2015 <- read.csv("/home/user/R/nzghg2015/crf-data-2015-0.csv", skip=2, header=TRUE, sep=",", colClasses ="numeric", nrows=27, na.strings=NA, dec=".", strip.white=TRUE)
# examine the dataframe
str(gsector2015)
data.frame: 26 obs. of 8 variables:
$ Year : num 1990 1991 1992 1993 1994 ...
$ Energy. : num 23748 24140 26041 25475 25762 ...
$ Industrial.processes.and.product.use..IPPU. : num 3584 3733 3378 3218 3098 ...
$ Agriculture. : num 33123 33471 33149 33364 34340 ...
$ Land.use..land.use.change.and.forestry..LULUCF.: num -30122 -32130 -31620 -32263 -32317 ...
$ Waste. : num 4118 4215 4301 4388 4323 ...
$ Net.emissions..including.LULUCF. : num 34451 33428 35250 34181 35206 ...
$ Gross.emissions..without.LULUCF. : num 64574 65559 66870 66444 67523 ...
# Simplify the column names (vector names)
colnames(gsector2015) <- c("Year", "Energy", "Industrial", "Agriculture", "LULUCF", "Waste", "Netemissions", "Grossemissions")

The final step is to make the chart.

png("NZ-ghgsector-2015-560.png", bg="white", width=560, height=420,pointsize = 14)
par(mar=c(2.7,2.7,1,1)+0.1)
plot(gsector2015[["Year"]],gsector2015[["Agriculture"]]/1000,ylim=c(-42,60), xlim=c(1989,2015),tck=0.01,axes=FALSE,ann=FALSE, type="n",las=1)
axis(side=1, tck=0.01, las=0, lwd = 1, at = c(1990:2015), labels = c(1990:2015), tick = TRUE)
axis(side=2, tck=0.01, las=2, line = NA,lwd = 1, at = c(-30,-20,-10,0,10,20,30,40), labels = c(-30,-20,-10,0,10,20,30,40),tick = TRUE)
axis(side=3, tck=0.01, at = c(1990:2015), labels = FALSE, tick = TRUE)
axis(side=4, tck=0.01, at = c(-30,-20,-10,0,10,20,30,40), labels = FALSE, tick = TRUE)
box(lwd=1)
lines(gsector2015[["Year"]],gsector2015[["Agriculture"]]/1000,col="#1b9e77",lwd=1)
points(gsector2015[["Year"]],gsector2015[["Agriculture"]]/1000,col="#1b9e77",cex=1,pch=7)
lines(gsector2015[["Year"]],gsector2015[["Energy"]]/1000,col="#d95f02",lwd=1)
points(gsector2015[["Year"]],gsector2015[["Energy"]]/1000,col="#d95f02",cex=1,pch=8)
lines(gsector2015[["Year"]],gsector2015[["Industrial"]]/1000,col="#7570b3",lwd=1)
points(gsector2015[["Year"]],gsector2015[["Industrial"]]/1000,col="#7570b3",cex=1,pch=9)
lines(gsector2015[["Year"]],gsector2015[["Waste"]]/1000,col="#e7298a",lwd=1)
points(gsector2015[["Year"]],gsector2015[["Waste"]]/1000,col="#e7298a",cex=1,pch=10)
lines(gsector2015[["Year"]],gsector2015[["LULUCF"]]/1000,col="#66a61e",lwd=1)
points(gsector2015[["Year"]],gsector2015[["LULUCF"]]/1000,col="#66a61e",cex=1,pch=11)
abline(h=0,col=1,lwd=1,lty=1)
text(1990,40,adj=0,"Agriculture + 16%",col=1,cex=1)
text(2015,26,adj=1,"Energy + 37%",col=1,cex=1)
text(1990,10,adj=0,"Waste - 3%",col=1,cex=1)
text(2015,10,adj=1,"Industry + 47%",col=1,cex=1)
text(2015,-18,adj=1,"Land Use & Forestry Removals -21%",col=1,cex=1)
mtext(side=1,line=-1.5,cex=0.8,"Data: New Zealand’s Greenhouse Gas Inventory 1990 – 2015, \nMfE 2017 Report ME 1309 http://www.mfe.govt.nz/node/23304/")
mtext(side=3,cex=1.5, line=-4,expression(paste("New Zealand Greenhouse Gas \nEmissions by Sector 1990 to 2015")) )
mtext(side=2,cex=0.9, line=-1.5,expression(paste("million tonnes C", O[2], "-e")))
mtext(side=4,cex=0.75, line=0.05,R.version.string)
dev.off()

06 June 2017

The latest inventory of New Zealand's greenhouse gases

On the Friday before last Friday, the 26 of May 2017, Minister for Climate Change Issues, Paula Bennett and the Ministry for the Environment released the latest inventory of New Zealand's greenhouse gases.

Minister Bennett and the Ministry have as their headline Greenhouse gas emissions decline.

I thought would I whip up a quick chart from the new data with R.

I pretty much doubted that there was any discernible decline in New Zealand's greenhouse gas emissions to justify Bennett's statement. We should always look at the data. Here is the chart of emissions from 1990 to 2015.

Although gross emissions (emissions excluding the carbon removals from Land Use Land Use Change and Forestry (LULUCF)) show a plateauing since the mid 2000s, with the actual gross emissions for the last few years sitting just below the linear trend line.

Gross 2015 emissions are still 24% greater than gross 1990 emissions.

For net emissions (emissions including the carbon removals from Land Use Land Use Change and Forestry) the data points for the years since 2012 sit exactly on the linear trend line. Net 2015 emissions are still 64% greater than net 1990 emissions.

There was of course more data wrangling and cleaning than I remembered from when I last made a chart of emissions!

The Ministry for the Environment's webpage for the Greenhouse Gas Inventory 2015 includes a link to a summary Excel spreadsheet. The Excel file includes two work-sheets.

One method of data-cleaning would be to save the two work sheets as two comma-separated values files after removing any formatting. I also like to reformat column headings by either adding double-speech marks or by concatenating the text into one text string with no spaces or by having a one-word header, say 'Gross' or 'Net'.

Of course, that's not what I did in the first instance!

Instead, I copied columns of data from the summary Excel sheet and pasted them into Convert Town's column to comma-separated list online tool. I then pasted the comma-separated lists into my R script file for the very simple step of assigning them into numeric vectors in R. Which looks like this.

net2015 <-c(34451.43, 33428.11, 35249.79, 34181.32, 35205.70, 37595.94, 40173.47, 41887.90, 39179.52,39583.29,42774.45,46205.88,49178.70,50470.09,50070.49,53676.77,55381.04,55146.23,46551.24,47416.85,47462.99,51792.44,54446.07,55242.18,56471.91,56372.51)
gross2015 <-c(64573.82, 65558.53, 66869.50, 66444.14, 67522.89, 68447.75,70592.31,73322.21,71020.33,73049.33,75142.80,77955.23,78519.60,80929.90,80530.14,82493.69,82550.94,80168.82,80204.79,77710.07,78077.20,77951.12,79929.55,79397.17,80267.87,80155.14)
year2015 <-c(1990:2015)

Then the script for the chart is:

png("NZ-ghg-2015-560.png", bg="white", width=560, height=420,pointsize = 14)
par(mar=c(2.7,2.7,1,1)+0.1)
plot(year2015,gross2015/1000,ylim=c(0,99.5), xlim=c(1989,2015),tck=0.01,axes=FALSE,ann=FALSE, type="n",las=1)
axis(side=1, tck=0.01, las=0, lwd = 1, at = c(1990:2015), labels = c(1990:2015), tick = TRUE)
axis(side=2, tck=0.01, las=2, line = NA,lwd = 1, at = c(0,10,20,30,40,50,60,70,80), labels = c(0,10,20,30,40,50,60,70,80),tick = TRUE)
axis(side=3, tck=0.01, at = c(1990:2015), labels = FALSE, tick = TRUE)
axis(side=4, tck=0.01, at = c(0,10,20,30,40,50,60,70,80), labels = FALSE, tick = TRUE)
box(lwd=1)
lines(year2015,gross2015/1000,col="#000099",lwd=1)
points(year2015,gross2015/1000,col="#000099",cex=1.3,pch=17)
abline(lm(gross2015/1000~year2015),col="#000099",lwd=2,lty=3)
text(2006,66,adj=0,"Gross + 24%",col="#000099",cex=1.6)
lines(year2015,net2015/1000,col="#CC0000",lwd=1)
points(year2015,net2015/1000,col="#CC0000",cex=1.3,pch=15)
abline(lm(net2015/1000~year2015),col="#CC0000",lwd=2,lty=3)
text(2007,35,adj=0,"Net + 64%",col="#CC0000",cex=1.6)
mtext(side=1,line=-1.5,cex=1,"Data: New Zealand’s Greenhouse Gas Inventory 1990 – 2015, \nMfE 2017 Report ME 1309 http://www.mfe.govt.nz/node/23304/")
mtext(side=3,cex=1.6, line=-4,expression(paste("New Zealand Gross & Net Greenhouse Gas \nEmissions 1990 to 2015")) )
mtext(side=2,cex=1.1, line=-1.8,expression(paste("million tonnes C", O[2], "-e")))
mtext(side=4,cex=0.75, line=0.05,R.version.string)
dev.off()

The result is that the two pieces of R script meet a standard of reproducible research, they contain all the data and code necessary to replicate the chart. Same data + Same script = Same results.

I also uploaded the chart to Wikimedia Commons and included the R script. Wikimedia Commons facilitates the use of R script by providing templates for syntax highlighting. So with the script included, the Wikimedia page for the chart is also reproducible. Here is the Wikimedia Commons version of the same chart.

NZ-ghg-2015

For comparison, here is my equivalent chart of greenhouse gas emissions for 1990 to 2010. Gross emissions up 20% and net emissions up 59%.

What can I say to sum up - other than Plus ça change, plus c'est la même chose.