# obtain data sheet from Statistics NZ
urlrawdata <- c("http://archive.stats.govt.nz/~/media/Statistics/browse-categories/economic-indicators/national-accounts/Long-term%20data%20series/D%20Government/table-d4-1.xls")
filerawdata <-c("table-d4-1.xls")
download.file(urlrawdata, filerawdata)
# load Readxl library
library(readxl)
# List all sheets in an excel spreadsheet
excel_sheets("table-d4-1.xls")
[1] "Data" "Documentation"
# read in debt as % of GDP from column "BW"
debt2gdp <-read_excel("table-d4-1.xls", sheet = "Data", range ="BW31:BW172", col_names = F, skip =30,col_types = c("numeric"))
# convert to time series object
debt2gdptimeseries <-ts(data = debt2gdp, start = 1860, end =2000)
# create svg format chart with 14 pt text font and grid lines via 'grid'
svg(filename="debt2gdptimeseriesnotitle_720by540.svg", width = 8, height = 6, pointsize = 14, onefile = FALSE, family = "sans", bg = "white", antialias = c("default", "none", "gray", "subpixel"))
par(mar=c(2.7,2.7,1,1)+0.1)
plot(debt2gdptimeseries,tck=0.01,ylim=c(0,250),xlim=c(1863,1998),axes=TRUE,ann=TRUE, las=1,col=2,lwd=2,type='l',lty=1)
grid(col="darkgray",lwd=1)
axis(side=4, tck=0.01, las=0,tick=TRUE,labels = FALSE)
mtext(side=1,cex=0.8,line=-1.3,"Data: Statistics NZ, Long-term data series, D4.1 Central government debt, table-d4-1.xls")
mtext(side=3,cex=1.7, line=-3.6,expression(paste("New Zealand Gross Core Government \nDebt 1860 to 2000")) )
mtext(side=2,cex=0.9, line=-1.3,"% of Real GDP (2000)")
mtext(side=4,cex=0.75, line=0.05,R.version.string)
dev.off()