library(csodata)
library(tidyverse)
library(knitr)
library(kableExtra)
library(ggplot2)
library(lubridate)
library(ggrepel)
library(zoo)
library(patchwork)
library(Hmisc)
library(formattable)
library(scales)
#Load
WPM28 <- cso_get_data("WPM28")
WPM28 <- WPM28 %>%
pivot_longer(!1:2, names_to = "year_month")
# Date transformation
WPM28$Month <- as.Date(paste(WPM28$year_month, "01", sep = "-"), "%YM%m-%d")
WPM28$Year <- year(WPM28$Month)
WPM28$Lag <- Lag(WPM28$value,1)
WPM28$Diff <- WPM28$value-WPM28$Lag
# Take year greater than or equal to 2019
WPM28 <- WPM28 %>%
filter(Year >= "2019")
WPM28_A <- WPM28%>%
filter(Statistic=="Wholesale Price Index (Excl VAT) for Building and Construction Materials")
WPM28_B <- WPM28%>%
filter(Statistic=="Percentage Change over 12 month in Wholesale Price Index")
WPM28_C <- WPM28%>%
filter(Statistic=="Percentage Change over 1 month in Wholesale Price Index")
WPM28_C_tail_1 <- tail(WPM28_C,1)
Wholesale Price Index for Building and Construction Materials has 40 Types of Materials. The series begins in January 2015.
Figures below for 2022M06
WPM28_C_A <- WPM28_C %>%
filter(year_month==max(year_month))
colourC_A <-ifelse(WPM28_C_A$value < 0,"#CC0000","#1b5545")
FigMonth<-ggplot(WPM28_C_A, aes(x=Type.of.Material, y=value))+
geom_col(alpha = 0.65, colour="#373634", fill = colourC_A)+
labs(title = "Percentage Change Month on Month in Wholesale Price Index")+
xlab("Type of Material")+
ylab("Percentage change")+
geom_text(aes(label=value), hjust = 1,size=3)+
theme(axis.text.x = element_text(angle=90))+
theme(axis.text.x=element_text(size=10))+
theme(legend.position="none")+
theme(axis.text = element_text(size = rel(1)))+
theme(plot.title=(element_text(vjust =2)))+
theme(panel.border = element_rect(linetype = 1, fill = NA))+
coord_flip()
FigMonth
Series below begin from January 2019
colour <-ifelse(WPM28_B$value < 0,"#CC0000","#1b5545")
Fig1<-ggplot(WPM28_B, aes(x=Month, y=value, group=Type.of.Material))+
geom_col(aes(group=Type.of.Material), alpha = 0.65, colour="#373634", fill = colour)+
labs(title = "Percentage Change over 12 month in Wholesale Price Index")+
xlab("Year-Month")+
ylab("Percentage change")+
scale_x_date(date_labels="%b-%Y",date_breaks ="3 month")+
geom_text_repel(aes(label=value),data = WPM28_B, size = 3)+
theme(axis.text.x = element_text(angle=90))+
theme(axis.text.x=element_text(size=10))+
theme(legend.position="none")+
theme(axis.text = element_text(size = rel(1)))+
theme(plot.title=(element_text(vjust =2)))+
theme(panel.border = element_rect(linetype = 1, fill = NA))
Fig1 + facet_wrap(~Type.of.Material, ncol = 2)
Black line (100) indicates 2015 as baseline
Fig2<-ggplot(WPM28_A, aes(x=Month, y=value, group=Type.of.Material, colour=Type.of.Material))+
geom_line(aes(group=Type.of.Material),size = 1.05, linetype=1, alpha = 0.65)+
labs(title = "Percentage Change over 12 month in Wholesale Price Index")+
xlab("Year-Month")+
ylab("2015 = 100")+
geom_hline(aes(yintercept=100),
colour= "#404040",
linetype = 1)+
scale_x_date(date_labels="%b-%Y",date_breaks ="3 month")+
theme(axis.text.x = element_text(angle=90))+
theme(axis.text.x=element_text(size=10))+
theme(legend.position="none")+
theme(axis.text = element_text(size = rel(1)))+
theme(plot.title=(element_text(vjust =2)))+
theme(panel.border = element_rect(linetype = 1, fill = NA))
Fig2 + facet_wrap(~Type.of.Material, ncol = 2)