library(tidyverse)
library(sf)

vic_map <- read_sf(here::here("data/vic-july-2018-esri/E_AUGFN3_region.shp")) |>
   # to match up with election data
   mutate(DivisionNm = toupper(Elect_div))

SA1map <- read_sf(here::here("data/Geopackage_2016_EIUWA_for_VIC/census2016_eiuwa_vic_short.gpkg"), 
                  layer = "census2016_eiuwa_vic_sa1_short")

🏂 Exercise 6A

Integrate data from different sources

SA1map <- read_sf(here::here("data/Geopackage_2016_EIUWA_for_VIC/census2016_eiuwa_vic_short.gpkg"),
   layer = "census2016_eiuwa_vic_sa1_short"
)
SA1map <- SA1map %>%
   mutate(centroid = st_centroid(geom)) %>%
   filter(Median_age_persons != 0)
ggplot(SA1map) +
   geom_sf(aes(geometry = centroid, color = Median_tot_prsnl_inc_weekly), shape = 3) +
   geom_sf(data = vic_map, aes(geometry = geometry), fill = "transparent", size = 1.3, color = "black") +
   coord_sf(xlim = c(144.8, 145.2), ylim = c(-38.1, -37.6)) +
   scale_color_viridis_c(name = "Median weekly\nperson income", option = "magma")

melb_geometry <- vic_map %>%
   filter(DivisionNm == "MELBOURNE") %>%
   pull(geometry)

MELB_SA1 <- SA1map %>%
   filter(st_intersects(centroid, melb_geometry, sparse = FALSE)[, 1])

fivenum(MELB_SA1$Median_tot_prsnl_inc_weekly)
## [1]    0.0  589.0  947.0 1130.5 1613.0
ggplot(MELB_SA1, aes(x = Median_tot_prsnl_inc_weekly)) +
   geom_histogram()

🗾 Exercise 6B

Compare with different a layer

SEDmap <- read_sf(here::here("data/Geopackage_2016_EIUWA_for_VIC/census2016_eiuwa_vic_short.gpkg"),
   layer = "census2016_eiuwa_vic_sed_short"
) %>%
   mutate(centroid = st_centroid(geom))

MELB_SED <- SEDmap %>%
   filter(st_intersects(centroid, melb_geometry, sparse = FALSE)[, 1])
## st_as_s2(): dropping Z and/or M coordinate
fivenum(MELB_SED$Median_tot_prsnl_inc_weekly)
## [1]  577.0  577.0  816.5 1056.0 1056.0

An estimate of the median total person weekly income is 947 dollars using SA1 data and 816.5 dollars using the SED data.

Material maintained and updated by Dr. Kate Saunders. Material originally developed by Dr. Emi Tanaka