Style the graph.
authorFrederik Vanrenterghem <frederik@vanrenterghem.biz>
Thu, 2 Nov 2017 14:10:21 +0000 (22:10 +0800)
committerFrederik Vanrenterghem <frederik@vanrenterghem.biz>
Thu, 2 Nov 2017 14:10:21 +0000 (22:10 +0800)
AU-taxstats.R

index 728c943c07940bd9c7a0770ece8a28d48b219774..76f9dcf00d2fc8f5bb644727e8e6aec73bb8e27a 100644 (file)
@@ -4,6 +4,7 @@ install.packages("devtools")
 devtools::install_github("tidyverse/ggplot2") # needed for geom_sf
 library(ggplot2)
 library(viridis)
+library(ggthemes)
 
 # Obtain the tax dataset if not available yet
 if(!file.exists("data/taxstats2015individual06ataxablestatusstateterritorypostcode.csv")) 
@@ -50,12 +51,22 @@ taxstats.POA$`Total.Income.or.Loss.no.`[is.na(taxstats.POA$`Total.Income.or.Loss
 # 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.`))
-sa3$incomeperearningcapita <- sa3$TotalIncome / sa3$TotalIncomeEarners
+sa3$incomeperearningcapita <- (sa3$TotalIncome / sa3$TotalIncomeEarners)/1000
 
 # As SA3s are still to narrow around cities compared to in the country,
 # let's simply look at Melbourne
 
 ggplot(dplyr::filter(sa3, data.table::`%like%`(GCC_NAME16, "Melbourne") )) +
   geom_sf(aes(fill = incomeperearningcapita, color = incomeperearningcapita)) +
-  scale_fill_viridis("incomeperearningcapita") +
-  scale_color_viridis("incomeperearningcapita")
+  scale_fill_viridis(name = "") +
+  scale_color_viridis(name = "") +
+  coord_sf(datum = NA) + # Work around https://github.com/tidyverse/ggplot2/issues/2071 to remove gridlines
+  labs(title = "Melbourne \nincome distribution",
+       subtitle = "2014/15, in 1000s AUD",
+       caption = "\nSource: Australian Taxation Office") +
+  theme_economist() +
+  theme(legend.position = "bottom",
+        legend.text = element_text(angle = 45, hjust = 1, size = 8),
+        axis.text = element_blank(),
+        axis.ticks = element_blank()) 
+