Correctly calculate the income.
[R/project-au-taxstats.git] / AU-taxstats.R
index bda1448b4102219f7a2f3c9d98d03c4a8cf012a9..e96c7a62a6a881c7331c596dcea96774d99b70e9 100644 (file)
@@ -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") +