#Data from US EIA International Energy Statistics http://www.eia.gov/cfapps/ipdbproject/IEDIndex3.cfm
<syntaxhighlight lang = "rsplus">
#Data from US EIA International Energy Statistics http://www.eia.gov/cfapps/ipdbproject/IEDIndex3.cfm
Year<-c(1980:2009)
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.045+ 91,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)
# read in US EIA energy production data in quadrillion BTU
pj<-c(p*1055*10^15)
# convert to joules
pej<-c(j/10^18)
# convert to exa joules
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)
# read in US EIA energy consumption data in quadrillion BTU
jc<-c(c*1055*10^15)
ejc<-c(jc/10^18)
library("RSVGTipsDevice")
devSVGTips(file="China-primary-energy-ej-2009v1.svg",toolTipMode=0,width=8.5,height=6.5)
par(mar=c(5,5,5,4)+0.1,cex.main=1.5,cex.lab=1)
plot(Year,ejc,las=1,ylim=c(0,95),type="n", main="China Total Primary Energy 1980 to 2009",xlab="Year", ylab="exajoules (10^18 joules)")
grid()
lines(Year,ejc,lwd=3,type="l",col=2)
lines(Year,ej,lwd=3,type="l",col=4)
mtext(side=1,line=-2.5,"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)
dev.off()