# 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") +