NZ and US petrol (‘gasoline’) and diesel prices by @ellis2013nz

Wait 5 sec.

[This article was first published on free range statistics - R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.This is another short, simple blog post building a chart I am going to be updating regularly as part of monitoring the impact of the slow-burn fuel crisis caused by the USA war with Iran.I have a page on this website with a few charts on the fuel crisis.Petrol (or gasoline) and diesel pricesHere’s today’s new chart.For those interested, here are some of the key features I thought through and are deliberately part of the polish here Both New Zealand and US prices on the same basis for direct comparability (and to shock USians with how much the rest of the world pays for gasoline). Mapping colour to country and using the facets for fuel type, rather than vice versa; doing it this way makes it easier to compare country-to-country (rather than fuel-to-fuel, which I found less interesting). Using colour in the title (thanks to ggtext by Claus O. Wilke and Brenton M. Wiernik) rather than a legend or direct labelling of the lines—very strong clutter-reduction technique in this context, I think. Annotations, in carefully chosen grey italics, to indicate the key events/periods of interest and answer the obvious questions that anyone looking at the chart (including me, this morning) would have eg “what happened in XXX?” Colours for countries chosen to suggest their flags. Make sure the audience understands the peculiar tax situation for diesel in New Zealand (diesel and electric vehicles pay a road user charge per distance travelled, not fuel consumed, which isn’t included in these prices). I considered, and eventually decided against, forcing the vertical axis scale to go down to zero. Still a bit unsure about this one, I see pros and cons of both options.I’ve also got a zoomed in version of the chart looking at just 2026. This is actually quite a bit less interesting. I like the big sweep of the past twenty years shown in the main chart, and the way we can link price changes to major events.Data sources and codeSo there’s nothing particularly complex in the code. I needed three data sources: New Zealand fuel prices, provided by the Ministry of Business, Innovation and Employment USA fuel prices provided by the Energy Information Administration NZD / USD exchange rate, which I have taken from FRED, the St Louis Federal Reserve data service.There were choices to make about exactly which series to match up and show, but not too difficult and I think I chose right.There’s also a bit of fiddling around to not download the data files every time the script is run, but only when the data is to some degree stale. The prices series are weekly so there’s no point hitting the provider’s server for yet another copy of the file when the last published observation was six days or less ago.library(tidyverse)library(janitor)library(readxl)library(patchwork)library(ggtext)#---------------New Zealand----------------------# Download petrol prices from MBIE. Not sure how to determine if it is 'stale'# or not, seems to get 10 days out of date at least.download.file( "https://www.mbie.govt.nz/assets/Data-Files/Energy/Weekly-fuel-price-monitoring/weekly-table.csv", destfile = "nz-petrol-prices.csv")# For some reason this crashes R# nz arrange(date) |> fill(DEXUSNZ, .direction = "down") |> mutate(value_usd_gallon = value * DEXUSNZ * 3.78541 / 100) |> mutate(fuel = ifelse(fuel == "Premium Petrol 95R", "Premium Petrol", fuel)) |> select(date, fuel, value_usd_gallon) |> mutate(country = "New Zealand")# Adjusted retail price is# "The national average price paid by consumers for a given fuel for the week. "# note, different from "Board price" which is the advertised rate Decided the# Adjusted retail price (i.e. what actually paid) was most comparable to the USA# series in the next section.#------------------USA---------------------# See https://www.eia.gov/dnav/pet/pet_pri_gnd_dcus_nus_w.htmstale_usa mutate(country = "USA")#------------combine the two----------------combined_petrol rbind(nz) |> filter(date >= min(nz$date)) |> filter(fuel != "Premium Petrol") |> mutate(fuel = fct_relevel(fuel, "Regular Petrol"))#-----------------plot drawing---------------annotations mutate(fuel = factor(fuel, levels = levels(combined_petrol$fuel)))# Base definition of chart, used in both versions:p0 ggplot(aes(x = date, y = value_usd_gallon, colour = country)) + facet_wrap(~fuel, ncol = 1) + geom_line(linewidth = 0.7) + scale_y_continuous(label = dollar) + scale_colour_manual(values = c("New Zealand" = "blue", "USA" = "red")) + labs( x = "", colour = "", y = "Price (USD per gallon)", title = "Retail petrol and diesel prices 2004-2026, **New Zealand** vs **USA**, (USD/gallon).", subtitle = "New Zealand prices include petrol excise, GST and other taxes but exclude diesel fuel excise.", caption = "Source: New Zealand MBIE, USA EIA" ) + theme(legend.position = "none", plot.title = element_markdown())# Main chart:p1