From: Frederik Vanrenterghem Date: Thu, 2 Nov 2017 13:24:27 +0000 (+0800) Subject: Correctly calculate the income. X-Git-Url: http://git.vanrenterghem.biz/R/project-au-taxstats.git/commitdiff_plain/27fd7330918faa446da55a75f9e455562cde7e99?ds=sidebyside Correctly calculate the income. --- diff --git a/AU-taxstats.R b/AU-taxstats.R index bda1448..e96c7a6 100644 --- a/AU-taxstats.R +++ b/AU-taxstats.R @@ -44,12 +44,13 @@ taxstats.sa3 <- merge(x = taxstats, y = sa3, by.x = "Postcode", by.y = "POA_CODE # 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 - +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 # Total income will be incorrect, as the POAs intersect with multiple SA3s -sa3$incomeperearningcapita <- as.vector(POA_SAs %*% as.matrix(taxstats.POA$incomeperearningcapita)) - +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.`)) +sa3$incomeperearningcapita <- sa3$TotalIncome / sa3$TotalIncomeEarners ggplot(sa3) + geom_sf(aes(fill = incomeperearningcapita, color = incomeperearningcapita)) + scale_fill_viridis("incomeperearningcapita") +