<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/are-petrol-prices-in-australia-fair/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://levashov.biz/are-petrol-prices-in-australia-fair/"> R – Alex Levashov – eCommerce Consultant (Melbourne, Australia)</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>Petrol is a product that used by most of Australians. So people are pretty sensitive to price changes, especially when the fuel become more expensive. With prices reaching $1.6 for unleaded the debates are becoming <a rel="nofollow" href="https://www.aph.gov.au/Parliamentary_Business/Petitions/House_of_Representatives_Petitions/Petitions_General/Petitions_List?id=EN0744" target="_blank">more and more hot</a>.</p>
<p>Are greedy petrol traders ripping off Australians or the price changes are fair and primarily defined by the factors such as FX rate and crude oil price? Official <a rel="nofollow" href="https://www.accc.gov.au/consumers/petrol-diesel-lpg/about-fuel-prices" target="_blank">point of view</a> from ACCC is the prices are mostly determined by international factors.</p>
<p>Let’s check, is it true or not using R and some simple data analysis and visualization techniques.  We’ll check how retail petrol price correlate with two major international factors that affects it – crude oil price and Australian dollar exchange rate.</p>
<h2>Get the data</h2>
<p>First we need to collect the data.  We need the next pieces of data:</p>
<ul>
<li>Crude oil price. It is usually calculated in USD for barrel</li>
<li>AUD to USD foreign exchange rate</li>
<li>Retail petrol prices in Australia</li>
</ul>
<p>I was able quite quickly get first 2 pieces of data, they are available at <a rel="nofollow" href="https://fred.stlouisfed.org/" target="_blank">FRED</a> up to 1980th in easy to use CSV format. I’ve just had to add couple final rows with the most recent data, did it manually.</p>
<p>Getting Aussie retail petrol prices were much harder. There is plenty of data available of current prices, but getting monthly historical data appeared to be a challenge to my surprise. The best I was able to get is <a rel="nofollow" href="https://www.fuelwatch.wa.gov.au/fuelwatch/pages/public/historicalPriceSearch.jspx" target="_blank">the data from Western Australia government agency</a> starting from early 2000th.  Taking into account that WA displays the shortest petrol <a rel="nofollow" href="https://www.accc.gov.au/consumers/petrol-diesel-lpg/petrol-price-cycles#petrol-price-cycles-in-capital-cities" target="_blank">price circle</a> it is probably good enough.</p>
<p>After a bit of data wrangling I was have produced the data frame with next columns:</p>
<ul>
<li>Date (month and year)</li>
<li>Crude oil price in AUD per barrel</li>
<li>Petrol price in AUD per litre</li>
</ul>
<p>Having oil price in AUD is important to account for FX rate fluctuation. You can get <a rel="nofollow" href="https://github.com/alevashov/oil-petrol-au/blob/master/petrol-oil.csv" target="_blank">full csv file</a> from my Github.</p>
<p>Let’s start making charts. I’ve used R package ggplot2 for this job.</p>
<h3>Crude oil price</h3>
<p>The piece of code below produce a chart of monthly crude oil price in Australian dollars since 2001.</p>
<p><code>df1 %>% ggplot(aes(date, oilaud)) +<br>
geom_line()+<br>
xlab(&quot;Date&quot;)+ylab (&quot;Price per barrel, $AUD&quot;)+<br>
ggtitle(&quot;Crude oil price&quot;)+<br>
theme_economist()</code></p>
<div class="wp-caption"><img sizes="(max-width: 767px) 100vw, 767px" src="https://i1.wp.com/levashov.biz/wp-content/uploads/2018/10/crude-oil-aud-2.png?w=450&ssl=1" alt="Crude oil price, AUD" class="wp-image-777" data-wp-pid="777" data-recalc-dims="1">
<p class="wp-caption-text">Crude oil price, AUD</p>
</div>
<p><em>dplyr</em> package is used to allow <strong>pipes</strong> (%>% syntax).</p>
<h3>Petrol retail prices</h3>
<p>Next let’s create retail petrol prices, the approach is very similar.</p>
<p>The code:</p>
<p><code>df1 %>% ggplot(aes(oilaud, petrol_price, color=factor(year(date)))) +<br>
geom_point(size=3)+<br>
xlab(&quot;Crude oil, $ per barrel&quot;)+ylab (&quot;Petrol, cents per liter&quot;)+<br>
ggtitle(&quot;Petrol vs crude oil&quot;)+<br>
theme_economist()</code></p>
<p>and the chart:</p>
<div class="wp-caption"><img sizes="(max-width: 767px) 100vw, 767px" src="https://i1.wp.com/levashov.biz/wp-content/uploads/2018/10/retail-petrol-aud.png?w=450&ssl=1" alt="Retail petrol prices, Australia" class="wp-image-776" data-wp-pid="776" data-recalc-dims="1">
<p class="wp-caption-text">Retail petrol prices, Australia</p>
</div>
<p>The charts looks quite similar isn’t it?</p>
<p>Let’s put them together.</p>
<h3>Crude oil with petrol</h3>
<p>ggplot2 allows quite easily to put 2 variables into one chart. Here is the code to do it:</p>
<p><code>df1 %>% ggplot(aes(date))+<br>
geom_line(aes(y=oilaud, colour= &quot;Oil&quot;))+<br>
geom_line(aes(y=petrol_price, colour=&quot;Petrol&quot;))+<br>
scale_y_log10()+<br>
xlab(&quot;Date&quot;)+ylab (&quot;Prices&quot;)+<br>
ggtitle(&quot;Retail petrol price vs crude oil price&quot;)+<br>
theme_economist()</code></p>
<p>Because we have retail prices in cents per litre and oil prices in dollars per barrel the numbers are quite similar and we don’t really need to make more complex things like changing scales, which we have to do for vastly different values.</p>
<div class="wp-caption"><img sizes="(max-width: 767px) 100vw, 767px" src="https://i0.wp.com/levashov.biz/wp-content/uploads/2018/10/oil-and-petrol-chart.png?w=450&ssl=1" alt="Crude oil and retail petrol prices" class="wp-image-778" data-wp-pid="778" data-recalc-dims="1">
<p class="wp-caption-text">Crude oil and retail petrol prices</p>
</div>
<p>Looks like the prices correlate, isn’t it?</p>
<p>Let’s make another visualization, scatterplot.</p>
<p>The code:</p>
<p><code>df1 %>% ggplot(aes(oilaud, petrol_price, color=factor(year(date)))) +<br>
geom_point(size=3)+<br>
labs(title = &quot;Petrol vs crude oil\n&quot;, x = &quot;Crude oil, $ per barrel&quot;, y = &quot;Petrol, cents per liter&quot;, color = &quot;Colors for years\n&quot;)+<br>
theme_economist()</code></p>
<p>We use here colours to represent years of the data and a bit different approach to make titles and legend.</p>
<div class="wp-caption"><img sizes="(max-width: 767px) 100vw, 767px" src="https://i0.wp.com/levashov.biz/wp-content/uploads/2018/10/petrol-vs-oil-scatter-all.png?w=450&ssl=1" alt="Crude oil and retail petrol prices scatterplot " class="wp-image-779" data-wp-pid="779" data-recalc-dims="1">
<p class="wp-caption-text">Crude oil and retail petrol prices scatter plot</p>
</div>
<p>Visually it seems that the correlation between crude oil price and retail petrol price is quite strong indeed.</p>
<p>Let’s calculate the correlation with R function</p>
<p><code>cor(df1$petrol_price, df1$oilaud)</code></p>
<p>The value returned is 0.9256118 which is a very strong correlation.</p>
<p>So it seems that overall petrol vendors are just passing the factors beyond their control (global oil price and FX rate) and there is nothing to worry about, all good. Or not?</p>
<h2>Have a closer look</h2>
<p>Probably you have noticed that while overall the dots on the scatter plot form the line, some of them well above it. And many of such dots are in the colours of recent years (2014-2018). What does it mean?</p>
<p>If the dots are above a trend line (imaginary in our case) they are out of general pattern, in our case the retail price is above the level we would expect with perfect correlation.</p>
<p>You may also notice that the crude oil price now is quite far from the highest point it, while current retail price is very close to historical maximum level.</p>
<p>The code below filter out subset of data when crude oil price was above AU$100</p>
<p><code>over100 &lt;- df1 %>% filter(oilaud >100)<br>
over100 %>%  ggplot(aes(oilaud, petrol_price, color=factor(year(date)))) +<br>
geom_point(size=3)+<br>
labs(title = &quot;Petrol retail in Australia vs crude oil, when crude oil over AU$100\n&quot;, x = &quot;Crude oil, $ per barrel&quot;, y = &quot;Petrol, cents per liter&quot;, color = &quot;Colors for years\n&quot;)+<br>
geom_hline(yintercept = 157.3)+<br>
geom_vline(xintercept = 104.29)+<br>
theme_economist()</code><br>
It produces the next scatter plot:</p>
<div class="wp-caption"><img sizes="(max-width: 767px) 100vw, 767px" src="https://i0.wp.com/levashov.biz/wp-content/uploads/2018/10/crude-oil-over-100.png?w=450&ssl=1" alt="Crude oil and retail petrol prices, oil over $100" class="wp-image-781" data-wp-pid="781" data-recalc-dims="1">
<p class="wp-caption-text">Crude oil and retail petrol prices, oil over $100</p>
</div>
<p>Vertical and horizontal black line intercepts on the most recent price point (begin of Oct 2018).</p>
<p>It is clear that:</p>
<ul>
<li>Current price is historically the second most expensive</li>
<li>In the past with the same crude oil price retail price was much lower – very often below $1.40 and always below $1.5</li>
<li>Similar retail price existed when crude oil price was close to $140 per barrel, over 20% more expensive than now</li>
</ul>
<p>So it looks like at the moment Australian consumers <strong>are being</strong> ripped off. But based on the history it shouldn’t last too long, so hopefully the prices soon return to more fair level.</p>
<p>All code and data available on <a rel="nofollow" href="https://github.com/alevashov/oil-petrol-au" target="_blank">Github</a></p>
<p><a rel="nofollow" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Flevashov.biz%2Fare-petrol-prices-in-australia-fair%2F&linkname=Are%20petrol%20prices%20in%20Australia%20fair%3F" title="Facebook" target="_blank"></a><a rel="nofollow" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Flevashov.biz%2Fare-petrol-prices-in-australia-fair%2F&linkname=Are%20petrol%20prices%20in%20Australia%20fair%3F" title="Twitter" target="_blank"></a><a rel="nofollow" href="https://www.addtoany.com/add_to/google_plus?linkurl=https%3A%2F%2Flevashov.biz%2Fare-petrol-prices-in-australia-fair%2F&linkname=Are%20petrol%20prices%20in%20Australia%20fair%3F" title="Google+" target="_blank"></a><a rel="nofollow" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Flevashov.biz%2Fare-petrol-prices-in-australia-fair%2F&linkname=Are%20petrol%20prices%20in%20Australia%20fair%3F" title="LinkedIn" target="_blank"></a><a rel="nofollow" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Flevashov.biz%2Fare-petrol-prices-in-australia-fair%2F&linkname=Are%20petrol%20prices%20in%20Australia%20fair%3F" title="Reddit" target="_blank"></a><a data-a2a-title="Are petrol prices in Australia fair?" rel="nofollow" href="https://www.addtoany.com/share#url=https%3A%2F%2Flevashov.biz%2Fare-petrol-prices-in-australia-fair%2F&amp;%23038;title=Are%20petrol%20prices%20in%20Australia%20fair%3F" data-a2a-url="https://levashov.biz/are-petrol-prices-in-australia-fair/" target="_blank"></a></p>
<p>The post <a rel="nofollow" href="https://levashov.biz/are-petrol-prices-in-australia-fair/" target="_blank">Are petrol prices in Australia fair?</a> appeared first on <a rel="nofollow" href="https://levashov.biz/" target="_blank">Alex Levashov – eCommerce Consultant (Melbourne, Australia)</a>.</p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://levashov.biz/are-petrol-prices-in-australia-fair/"> R – Alex Levashov – eCommerce Consultant (Melbourne, Australia)</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/mm6uQn_eQSU" height="1"></a></div>