From 49286c850b490d5617b8eaf4485671f52d264a7e Mon Sep 17 00:00:00 2001 From: Frederik Vanrenterghem Date: Thu, 2 Nov 2017 21:20:21 +0800 Subject: [PATCH 1/1] Plot income per SA3. --- AU-taxstats.R | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/AU-taxstats.R b/AU-taxstats.R index d5e3c82..bda1448 100644 --- a/AU-taxstats.R +++ b/AU-taxstats.R @@ -30,3 +30,27 @@ ggplot(taxstats.POA) + geom_sf(aes(fill = incomeperearningcapita, color = incomeperearningcapita)) + scale_fill_viridis("incomeperearningcapita") + scale_color_viridis("incomeperearningcapita") + +# Let's try by SA3 +if(!file.exists("data/1270055001_sa3_2016_aust_shape.zip")) + download.file(url = "http://www.abs.gov.au/AUSSTATS/subscriber.nsf/log?openagent&1270055001_sa3_2016_aust_shape.zip&1270.0.55.001&Data%20Cubes&43942523105745CBCA257FED0013DB07&0&July%202016&12.07.2016&Latest", destfile = "data/1270055001_sa3_2016_aust_shape.zip") + +if(!file.exists("data/SA3_2016_AUST.shp")) + unzip(zipfile = "data/1270055001_sa3_2016_aust_shape.zip", exdir = "data/") + +sa3 <- st_read(dsn = "data/", layer = "SA3_2016_AUST", stringsAsFactors = FALSE) +taxstats.sa3 <- merge(x = taxstats, y = sa3, by.x = "Postcode", by.y = "POA_CODE16", all.y = TRUE) + +# Create a matrix of intersecting postal codes and SA3's + +POA_SAs <- st_intersects(x=sa3, y=POA, sparse=FALSE) +taxstats.POA$incomeperearningcapita[is.na(taxstats.POA$incomeperearningcapita)] <- 0 + +# Perform matrix multiplication to obtain the income metrix per SA3 +# Total income will be incorrect, as the POAs intersect with multiple SA3s +sa3$incomeperearningcapita <- as.vector(POA_SAs %*% as.matrix(taxstats.POA$incomeperearningcapita)) + +ggplot(sa3) + + geom_sf(aes(fill = incomeperearningcapita, color = incomeperearningcapita)) + + scale_fill_viridis("incomeperearningcapita") + + scale_color_viridis("incomeperearningcapita") -- 2.39.5