# Statistics NZ Tatauranga Aotearoa https://www.stats.govt.nz/indicators/greenhouse-gas-concentrations
# link to zip file 17/08/2024
download.file("https://www.stats.govt.nz/assets/Uploads/Environment-indicators-2023/Greenhouse-gas-concentrations/Download-data/greenhouse-gas-concentrations-data-to-2022.zip","greenhouse-gas-concentrations-data-to-2022.zip")
# unzip downloaded zip file
unzip("greenhouse-gas-concentrations-data-to-2022.zip")
# read in the data file
ghgs <- read.csv("greenhouse-gas-concentrations-monthly-2022.csv")
# select only methane records
methane <- ghgs[ghgs[["variable"]]=="methane",]
# select only mean fitted data
meanfitmethane <- methane[methane[["parameter"]]=="mean_fitted",]
# add date column
meanfitmethane[["date"]] = seq(as.Date('1989-08-31'), by = 'months', length = nrow(meanfitmethane))
# plot
svg(filename="NZmethane-2019-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,3.3,1,1)+0.1)
plot(meanfitmethane[["date"]],meanfitmethane[["greenhouse_gas_concentration"]],tck=0.01,ylab=NA,axes=T,ann=T, type="l",lwd=2,las=1,col="#7570B3")
grid(col="darkgray",lwd=1)
axis(side=4, tck=0.01, las=0,tick=TRUE,labels = FALSE)
box(lwd=1)
mtext(side=1,line=-1.4,cex=1,"Data: Stats NZ Tatauranga Aotearoa \nhttps://www.stats.govt.nz/indicators/greenhouse-gas-concentrations")
mtext(side=3,cex=1.3, line=-1.8,expression(paste("Baring Head Methane concentrations 1989 to 2022")) )
mtext(side=2,cex=1.1, line=-1.5,expression(paste("Parts per billion")))
mtext(side=4,cex=0.75, line=0.05,R.version.string)
dev.off()