X-Git-Url: http://git.vanrenterghem.biz/R/project-au-taxstats.git/blobdiff_plain/8a23a6086193c79ff00a532f2b4d893e741e7ba9..26a2a71b8ad239147ec5bc61915ec1237832bd87:/AU-taxstats.R diff --git a/AU-taxstats.R b/AU-taxstats.R index 8bbcb26..1ca7b75 100644 --- a/AU-taxstats.R +++ b/AU-taxstats.R @@ -41,14 +41,13 @@ 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$`Total.Income.or.Loss..`[is.na(taxstats.POA$`Total.Income.or.Loss..`)] <- 0 taxstats.POA$`Total.Income.or.Loss.no.`[is.na(taxstats.POA$`Total.Income.or.Loss.no.`)] <- 0 -# Perform matrix multiplication to obtain the income metrix per SA3 +# Perform matrix multiplication to obtain the income metrics per SA3 # Total income will be incorrect, as the POAs intersect with multiple SA3s sa3$TotalIncome <- as.vector(POA_SAs %*% as.matrix(taxstats.POA$`Total.Income.or.Loss..`)) sa3$TotalIncomeEarners <- as.vector(POA_SAs %*% as.matrix(taxstats.POA$`Total.Income.or.Loss.no.`)) @@ -65,8 +64,10 @@ cities = c("Perth","Melbourne","Sydney","Adelaide","Brisbane") plots <- function() {lapply(cities, function(x){ plot <- ggplot(dplyr::filter(sa3, data.table::`%like%`(GCC_NAME16, x) )) + geom_sf(aes(fill = incomeperearningcapita, color = incomeperearningcapita)) + - scale_fill_viridis(name = "") + - scale_color_viridis(name = "") + + scale_fill_viridis(name = "", + limits = c(min(sa3$incomeperearningcapita, na.rm = TRUE),max(sa3$incomeperearningcapita, na.rm = TRUE))) + + scale_color_viridis(name = "", + limits = c(min(sa3$incomeperearningcapita, na.rm = TRUE),max(sa3$incomeperearningcapita, na.rm = TRUE))) + coord_sf(datum = NA) + # Work around https://github.com/tidyverse/ggplot2/issues/2071 to remove gridlines labs(title = paste0(x," \nincome distribution"), subtitle = "2014/15, in 1000s AUD", @@ -80,4 +81,4 @@ plots <- function() {lapply(cities, function(x){ }) } -saveGIF(plots(),movie.name = "AUCitiesIncomeDistribution.gif", interval = 2) +saveGIF(plots(),movie.name = "AUCitiesIncomeDistribution.gif", interval = 2, loop = 2)