Skip to content

Instantly share code, notes, and snippets.

@aaronschiff
Created August 10, 2017 03:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaronschiff/23056e40139657d186a59af346a2d0e6 to your computer and use it in GitHub Desktop.
Save aaronschiff/23056e40139657d186a59af346a2d0e6 to your computer and use it in GitHub Desktop.
Make a simple chart of property prices from MBIE/MfE urban development capacity data
# -----------------------------------------------------------------------------
# Setup
library(magrittr)
library(lubridate)
library(tidyverse)
library(ggplot2)
library(scales)
source("clean-ggplot-theme.R")
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# MBIE/MfE Urban Development Capacity data
# Load property data
dat_au <- read_csv("AU.csv")
names(dat_au) <- tolower(names(dat_au))
dat_au %<>%
mutate(date = yq(paste(year(date), quarter(date), sep = "-"))) %>%
arrange(name, date)
# Load 2013 areas table
areas2013 <- read_csv("2013_Areas_Table.csv")
# Join region to sales data by AU code
dat_au %<>%
left_join(areas2013 %>%
select(AU2013_code, REGC2013_label) %>%
distinct(),
by = c("code" = "AU2013_code"))
# Plot median_sp_real by quarter for all area units
chart_median_sp_real <- dat_au %>%
ggplot() +
geom_line(aes(x = date, y = median_sp_real, group = code),
colour = rgb(0, 0, 0, 0.03)) +
xlab("") +
ylab("") +
scale_y_continuous(labels = comma,
limits = c(0, 3000000),
breaks = seq(0, 3000000, 500000)) +
clean_theme()
print(chart_median_sp_real)
# Plot median_sp_real by quarter, highlight Auckland area units
chart_median_sp_real_auckland_highlight <- dat_au %>%
mutate(region_group = ifelse(REGC2013_label == "Auckland Region", "Auckland", "All other regions")) %>%
ggplot() +
geom_line(aes(x = date, y = median_sp_real, group = code, colour = region_group)) +
xlab("") +
ylab("") +
ggtitle("Median real selling price for census area units (2017 dollars)") +
scale_y_continuous(labels = comma,
limits = c(0, 3000000),
breaks = seq(0, 3000000, 500000)) +
scale_colour_manual(values = c("Auckland" = rgb(0, 0, 0, 0.1),
"All other regions" = rgb(0, 0, 0, 0.06)),
guide = FALSE) +
facet_wrap("region_group", nrow = 2, ncol = 1) +
clean_theme(base_size = 22)
png("cau-median-prices.png", width = 1600, height = 1200)
print(chart_median_sp_real_auckland_highlight)
dev.off()
# -----------------------------------------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment