library(forecast)
library(bsts)
library(ggplot2)
library(dplyr)
library(ggthemes)
library(tseries)
library(pracma)
library(seasonal)Some Visualization
Data Source
Has this data set been seasonally adjusted?
I have no clue
Let’s get some packages loaded first!
df0$Housing.estimates<-factor(df0$Housing.estimates)
df0$Type.of.unit<-factor(df0$Type.of.unit)
df0$REF_DATE<-as.Date(paste0(as.character(df0$REF_DATE), "-01"), format="%Y-%m-%d")#df0df0%>%select(REF_DATE,VALUE,Housing.estimates,Type.of.unit)%>%
filter(Housing.estimates == "Housing starts")%>%
ggplot(aes(x=REF_DATE,y=VALUE,col=Type.of.unit))+geom_line()+
geom_point()+labs(x="Year",y="Units Started",col="Types")+ggtitle("Units Started in Canada from 2014-09 to 2022-12")+
theme_stata(scheme = "s1color")+scale_color_stata()+
scale_x_date(date_breaks = "3 month", date_labels = "%Y-%m")+
theme(axis.text.x = element_text(angle = 90, hjust = 1))df0%>%select(REF_DATE,VALUE,Housing.estimates,Type.of.unit)%>%
filter(Housing.estimates == "Housing completions")%>%
ggplot(aes(x=REF_DATE,y=VALUE,col=Type.of.unit))+geom_line()+
geom_point()+labs(x="Year",y="Units Completed",col="Types")+ggtitle("Units Completed in Canada from 2014-09 to 2022-12")+
theme_stata(scheme = "s1color")+scale_color_stata()+
scale_x_date(date_breaks = "4 month", date_labels = "%Y-%m")+
theme(axis.text.x = element_text(angle = 90, hjust = 1))By different types
df0%>%select(REF_DATE,VALUE,Housing.estimates,Type.of.unit)%>%
filter(Type.of.unit == "Total units")%>%
ggplot(aes(x=REF_DATE,y=VALUE,col=Housing.estimates))+geom_line()+
geom_point()+labs(x="Year",y="Units Completed",col="Types")+ggtitle("Units Completed in Canada from 2014-09 to 2024-01")+
theme_stata(scheme = "s1color")+scale_color_stata()+
scale_x_date(date_breaks = "3 month", date_labels = "%Y-%m")+
theme(axis.text.x = element_text(angle = 90, hjust = 1))df0$Year<-format(df0$REF_DATE, "%Y")
yearly_data<-df0%>%
group_by(Year, Housing.estimates) %>%
summarise(total_v = sum(VALUE, na.rm = TRUE), .groups = 'drop') %>%
ungroup()
yearly_data_filtered<-yearly_data %>%
filter(!Year %in% c(2014, 2023, 2024))yearly_data_filtered%>%
ggplot(aes(x = Year, y = total_v, fill = Housing.estimates)) +
geom_bar(stat = "identity", position = "dodge") +
theme_stata(scheme = "s1color")+scale_color_stata()+
labs(x="Year",
y="Estimated Total Units",
title="Total Housing Estimates by Year",
fill = "Housing Estimates")