## 30 January 2013

### China's primary energy

I have made a chart showing the trend in China's primary energy production and consumption.

I got the raw data from International Energy Statistics part of the US Energy Information Administration webpage. I downloaded two sets of time series data, production and cosumption, from 1980 to 2011 as Excel spreadsheets. I opened each sheet with a spreadsheet program (Gnumeric) and saved each file as a comma separated values file. I then opened each CSV file with a text editor and copied the numbers separated by commas into the script sheet of Rkward, the script editor I use with R.

That made it easy to read the data into R

China Total Primary Energy Consumption (Quadrillion Btu)
c<-c(17.28743,17.19205,17.93384,19.00967,20.45343,22.00581,23.23741,24.75911,26.4463,26.95795,26.9986,28.15789,29.26607,30.03293,34.11018,34.75689,35.5535,37.74754,37.03911,36.51697,36.35199,38.41189,43.90983,51.15546,62.9191,68.2469,72.89202,77.29039,84.67288,90.25787)

Being American, the data is expressed in the bizarre unit Quadrillion British thermal units (BTU) WTF? It's the amount of energy needed to heat one pound of water by one degree Fahrenheit. Not even the British use the BTU. The conversion factor to joules is 1 Quadrillion BTU = 1055 × 10^15 joules.

jc<-c(c*1055*10^15)
str(jc)
#num [1:30] 1.82e+19 1.81e+19 1.89e+19 2.01e+19 2.16e+19 ...(telling us the data is a numeric R object, consisting of 30 numbers )
max(jc)
# 9.522205e+19 (the maximum number in the data series is 9.522205 x 10^19)
ejc<-c(jc/10^18) #convert data from joules to exajoules
max(ejc)
 95.22205
p<-c(18.12198,17.9451,18.92106,20.2361,22.12683,24.30279,25.04091,25.93877,27.14594,28.77554,29.38537,29.62193,30.32492,31.97204,34.13204,35.04591,35.668,37.81456,36.38594,34.99918,34.19953,37.5048,42.8456,49.44335,59.38067,64.44807,66.78499,70.841,78.34819,81.88698) #China Total Primary Energy Production
pj<-c(p*1055*10^15)
pej<-c(j/10^18)
Year<-c(1980:2009) # need a time integer
png("China-primary-energy-ej-2009v1.png", width=650, height=500, pointsize = 16)
plot(Year,ejc,las=1,ylim=c(0,95),type="n",cex.main=1.6, cex.lab=1.2, main="China Total Primary Energy 1980 to 2009",xlab="Year", ylab="exajoules (10^18 joules)")
lines(Year,ejc,lwd=3,type="l",col=2)
lines(Year,pej,lwd=3,type="l",col=4)
mtext(side=1,line=-2,"Data: US EIA")
legend("top",bty='n',bg="white", c("Energy consumption","Energy production"),lty = 1,lwd=3,col = c(2,4))
box(lwd=2)
grid()
dev.off()

Give that a go!