Student Details

Data Source

Load R packages

library(ggplot2)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(XML)
library(RCurl)
## Loading required package: bitops

Load dataset

GDP_HHdebt <- read.csv("GDP_HHDebt.csv")

Code and Visualisation

# Create an object for the plot, start the ggplot by specifiying the dataset and variables
plot1 <- ggplot(GDP_HHdebt, aes(x = HouseHold_Debt, y = Savings))

# add a line of best fit before plotting the points to ensure it appears below the points on the final plot
plot1 <- plot1 + geom_smooth(alpha=0.15, method="lm", color="light grey")

# add a layer for the plot type (point/scatter), colour the points by region
plot1 <- plot1 + geom_point(aes(colour = Region), size = 2) + theme_bw(base_size = 16)

# add title, make main and legend titles bold for better clarity
plot1 <- plot1 + ggtitle("Household Debt vs Savings", subtitle = "by country, 2015") +
theme(plot.title = element_text(lineheight=.8, face="bold"), legend.title = element_text(lineheight=.8, face="bold")) + theme(plot.title = element_text(hjust = 0.5)) 

# label x and y axis
plot1 <- plot1 + xlab("Household Debt \n(% of net disposable income)") + ylab("Household Savings \n(% of net disposable income)")

# Add annotations; Australia = country of target audience. Switzerland, Dnemark, Greece & Latvia = outliers. USA = reference.
plot1 <- plot1 + annotate("text", x = 170, y = 6.4, label = "Australia", size = 5) + annotate("text", x = 116, y = -14, label = "Greece", size = 5) + annotate("text", x = 74, y = -8, label = "Latvia", size = 5) + annotate("text", x = 240, y = 16.5, label = "Switzerland", size = 5) + annotate("text", x = 281, y = 4.6, label = "Denmark", size = 5) + annotate("text", x = 129, y = 7.5, label = "USA", size = 5) 
plot1