R – ggplot2

The recent news reported that there has been a remarkable turnaround in the Irish housing market. House prices in Dublin were rising at a rate of over 20% a year. I decided to create a line chart to see how the housing prices were for the past 15 years. My first step was going to the Environment, Community and Local Government website to retrieve the relevant data.

I downloaded the document, extract and cleanse the data that I wanted and saved it as a csv file named “houseprice.csv”. I opened the csv file in R with the syntax:

houseprice <- read.csv(“houseprice.csv”, header=TRUE, skip=2)

I have removed the first 2 lines of the file as there were a title and an empty row.

I installed the gglot2 package with the syntax: install.packages(‘ggplot2’,dep=TRUE) and then loaded the ggplots package with the syntax: library(ggplot2).

Now I started plotting my line chart. The syntax to get the basic line graph by using ggplot2 and the result as below:

ggplot(data=houseprice, aes(x=year, y=Prices, group=Category)) + geom_line()

 

Plot1

I then changed the line colour and the line thickness, and also labelled the title, x and y axis. This was the syntax:

ggplot(data=houseprice, aes(x=year, y=Prices, group=Category, colour=Category)) + geom_line(size=1.5) +
ggtitle(“Average House & Apartment Prices”) +
labs(x=”Year”, y=”Prices in Euro”)

Plot2

I continued to format the chart by changing the scales for x-axis and y-axis. I wanted x-axis to display every single year instead every five years. I changed the y-axis so that the axis unit is 20,000 instead of 50,000. I also edited the font to different sizes for the plot title, legend labels, axis titles and axis labels. I bolded the plot title and axis title and changed the colour of the axis texts to black to make it more visible. I have removed the legend title as it was not required. I moved the position of the legend inside the graph.

This was the syntax:

ggplot(data=houseprice, aes(x=year, y=Prices, group=Category, colour=Category)) + geom_line(size=1.5) +
ggtitle(“Average House & Apartment Prices”) +
labs(x=”Year”, y=”Prices in Euro”) +
scale_x_continuous(breaks=seq(2000,2014,1)) +
scale_y_continuous(breaks=seq(140000,420000,20000)) +
theme(plot.title = element_text(face=”bold”, size=11)) +
theme(axis.title = element_text(face=”bold”, size=9)) +
theme(axis.text.x = element_text(colour=”black”, size=7)) +
theme(axis.text.y = element_text(colour=”black”, size=7)) +
theme(legend.title = element_blank()) +
theme(legend.text = element_text(size=8)) +
theme(legend.position=c(.9, .85))

This was the final result of my line graph.

Plot3

From the line graph, we could quickly see that Dublin has the highest house and apartment prices as compared to Cork and the whole country. House prices in Ireland were at their peak in year 2007.

In general, house prices had a positive constant growth from year 2000 till year 2007. It had decreased dramatically within 2 years from year 2007 till year 2009. It had continued to drop till year 2012. From year 2012, the house prices had shown the sign of recovery for the whole nation.

Dublin house prices had recovered in year 2010, 2 years earlier as compared to the whole nation. However the price growth did not sustain and it had dropped after 1 year. From year 2012 onward, Dublin house prices had a positive increased due to the on-going recovery.

It would be interesting to compare the average house and apartment prices with the domestic economy in Ireland from year 2000 to year 2014. We could study if there is any correlation between economy and house prices, what are the relationships between these two variables. By building up a linear regression modeling, we can learn how the economy can affect the house prices and make a prediction.

Besides that, we could look at the dataset of the numbers of completed new houses versus the average house prices in Ireland for the above duration. By using visualization, we could easily study how supply and demand of houses will affect the movement of the house prices. We could analyze developments in the housing market and predict the future investment opportunities in the property market.

We also could examine the raw building materials prices and labour costs. Check if there is any relationship between these elements against house prices in Ireland. Investigate how these elements can affect the house prices and do these elements have a strong positive correlation toward house prices.

Leave a Reply

Your email address will not be published. Required fields are marked *