With recent unprecedented increases in the price of fuel worldwide, it prompted the question of how have fuel prices for petrol and diesel changed in the last 20 years within the UK? Fuel prices have a wide impact on many aspects of life and are a useful indicator for the state of a country’s economy.
Data was obtained from Government National Statistics, reported by the Department for Energy Security and Net Zero. Data was the weekly road fuel prices table which reports the cost of unleaded petrol (ULSP) and unleaded diesel from 9/06/2013 until present day.
raw_data <- read_excel(here('Data','Weekly_Fuel_Prices.xlsx'), #loading data
skip=7, #skipping first 7 lines
sheet='All years') #selecting sheet titled "All Years"
Due to formatting of the Excel workbook I skipped the first 7 lines of the sheet in order for the data to load correctly and specify the page of the workbook I wanted data to be loaded from.
Date | ULSP: Pump price (p/litre) | ULSP: Diff on previous WEEK (p/litre) | ULSP: Diff on previous YEAR (p/litre) | Duty rate ULSP (p/litre) | VAT (% rate) ULSP | ULSD: Pump price (p/litre) | ULSD: Diff on previous WEEK (p/litre) | ULSD: Diff on previous YEAR (p/litre) | Duty rate ULSD (p/litre) | VAT (% rate) ULSD |
---|---|---|---|---|---|---|---|---|---|---|
2003-06-09 | 74.59028 | NA | NA | 45.82 | 17.5 | 76.77339 | NA | NA | 45.82 | 17.5 |
2003-06-16 | 74.46914 | -0.121141 | NA | 45.82 | 17.5 | 76.68905 | -0.084340 | NA | 45.82 | 17.5 |
2003-06-23 | 74.42357 | 0.000000 | NA | 45.82 | 17.5 | 76.62055 | -0.068508 | NA | 45.82 | 17.5 |
2003-06-30 | 74.35242 | -0.071145 | NA | 45.82 | 17.5 | 76.50526 | -0.115286 | NA | 45.82 | 17.5 |
#create clean_data
clean_data <- raw_data %>%
#rename variables ULSP and ULSD to Petrol and Diesel
rename("Petrol"="ULSP: Pump price (p/litre)",
"Diesel"="ULSD: Pump price (p/litre)") %>%
#select only variables date, Diesel and Petrol
select(Date,Petrol,Diesel)
Then I converted the data frame to long format.
df <- pivot_longer(clean_data,-Date, names_to="Cat", values_to="Value")
Date | Cat | Value |
---|---|---|
2003-06-09 | Petrol | 74.59028 |
2003-06-09 | Diesel | 76.77339 |
2003-06-16 | Petrol | 74.46914 |
2003-06-16 | Diesel | 76.68905 |
2003-06-23 | Petrol | 74.42357 |
2003-06-23 | Diesel | 76.62055 |
plot1 <- ggplot(df, aes(x=Date,y=Value,colour=Cat))+
geom_line(linewidth=0.75)+
#titles and legends
labs(title="Fuel Prices Over the Past 20 Years",x="Date",y="Pence Per Litre",color=NULL)+
#assign colours to Petrol and Diesel
scale_color_manual(limits=c("Petrol","Diesel"),values=wes_palette("Royal1",n=2))+
#adjust scale breaks
scale_x_datetime(date_breaks="1 year",date_labels="%Y")+
scale_y_continuous(breaks=c(80,100,120,140,160,180,200))+
#changing position and size of legends and labels
theme_bw()+
theme(axis.text.x=element_text(angle=50,hjust=1),
legend.position = "bottom",
plot.title=element_text(size=20,hjust=0.5),
legend.text=element_text(size=10),
legend.key.size=unit(1,"cm"))
#save output
ggsave("Fuel Prices 2003-2023.pdf", plot1, path=here("Plots"))
Next time with more data and time, I would investigate potential relationships between fuel prices and other factors such as government party in power. I would also include a measure of inflation to create a relative baseline.