library(RColorBrewer)
# read in data
data <- read.csv("https://www.mbie.govt.nz/assets/Data-Files/Energy/Weekly-fuel-price-monitoring/weekly-table.csv")
# Add a date column in date format
data[["Week_ending_Friday"]] <- as.Date(data[["Week_ending_Friday"]])
# create data frame of regular petrol price components , all rows of columns 1 and 16 to 23
petrol <- data[,c(1,16:23)]
# set some colours
display.brewer.pal("Dark2",n=5)
brewer.pal("Dark2",n=5)
[1] "#1B9E77" "#D95F02" "#7570B3" "#E7298A" "#66A61E"
tint <-c("#1B9E77", "#D95F02", "#7570B3", "#E7298A", "#66A61E")
# create chart
svg(filename ="Petrol-prices-ETS-2010-2023.svg", width = 8, height = 6, pointsize = 10, onefile = FALSE, family = "sans", bg = "white", antialias = c("default", "none", "gray", "subpixel"))
par(mar=c(4,2.9,1,1)+0.1)
plot(petrol[["Date"]],petrol[["Regular_Petrol_main_port_price_NZc.p.l"]],axes=T,ann=T, ylim=c(0,330),tck=0.01, type="l", col=tint[1],lwd=1, las=1 , ylab="",xlab="")
lines(petrol[["Date"]],petrol[["Regular_Petrol_importer_cost_NZc.p.l"]],type="l", col=tint[2],lwd=1)
lines(petrol[["Date"]],petrol[["Regular_Petrol_taxes_NZc.p.l"]],type="l", col=tint[3],lwd=1)
lines(petrol[["Date"]],petrol[["Regular_Petrol_GST_NZc.p.l"]],type="l", col=tint[4],lwd=1)
lines(petrol[["Date"]],petrol[["Regular_Petrol_ETS_NZc.p.l"]],type="l", col=tint[5],lwd=1)
legend("topleft", inset=c(0.0,0.0), cex=1.1,bty="n",c("Retail price","Import cost","Fuel excise tax","GST","Emissions trading scheme cost"), col=tint,lty=1,lwd=1)
mtext(side=4,cex=0.75, line=0.05,R.version.string)
mtext(side=1,line=2.75,cex=0.85,"Data: Ministry of Business Innovation & Employment\nhttps://www.mbie.govt.nz/assets/Data-Files/Energy/Weekly-fuel-price-monitoring/weekly-table.csv")
mtext(side=3,cex=1.6, line=-4,expression(paste("New Zealand petrol price \ncomponents 2010 to 2023")))
mtext(side=2,cex=1, line=-1.3,"cents per litre")
axis(side=4, tck=0.01, at = NULL, labels = FALSE, tick = TRUE)
dev.off()