class: middle center hide-slide-number monash-bg-gray80 .info-box.w-50.bg-white[ These slides are viewed best by Chrome or Firefox and occasionally need to be refreshed if elements did not load properly. See <a href=lecture-06.pdf>here for the PDF <i class="fas fa-file-pdf"></i></a>. ] <br> .white[Press the **right arrow** to progress to the next slide!] --- class: title-slide count: false background-image: url("images/bg-01.png") # .monash-blue[ETC5512: Wild Caught Data] <h1 class="monash-blue" style="font-size: 30pt!important;"></h1> <br> <h2 style="font-weight:900!important;">Combining Australian census and election data</h2> .bottom_abs.width100[ Lecturer: *Kate Saunders* Department of Econometrics and Business Statistics <i class="fas fa-envelope"></i> ETC5512.Clayton-x@monash.edu <i class="fas fa-calendar-alt"></i> Week 6 <br> ] --- class: center middle bg-gray .aim-box.tl.w-70[ Today you will: - look at the ABS geographical boundaries for the 2021 census - integrate data from different sources (census and election) to make exploratory inferences ] -- .aim-box.tl.w-70[ Coding Perspective: - Further expand our understanding of how to read and use spatial data in R - Better understand how spatial data is organised - Learn how to intersect two spatial objections - Practice re-projecting maps ] --- # Recall <i class="fas fa-database"></i> 2021 Federal Election Data .f6[ ```r library(tidyverse) library(sf) *aec_map <- read_sf(here::here("data/vic-july-2021-esri/E_VIC21_region.shp")) *votes <- read_csv("https://results.aec.gov.au/27966/Website/Downloads/HouseDopByDivisionDownload-27966.csv", skip = 1) electoral_winners = votes |> mutate(DivisionNm = toupper(DivisionNm)) |> filter(Elected == "Y") |> select(PartyAb, DivisionID, DivisionNm, Elected) |> distinct() aec_map = aec_map |> mutate(Elect_div = toupper(Elect_div)) winners_with_map = electoral_winners |> left_join(aec_map, by = c("DivisionNm" = "Elect_div")) aus_colours <- c( "ALP" = "#DE3533", "LNP" = "#ADD8E6", "KAP" = "#8B0000", "GVIC" = "#10C25B", "XEN" = "#ff6300", "LP" = "#0047AB", "NP" = "#0a9cca", "IND" = "#000000" ) ggplot(winners_with_map) + geom_sf(aes(fill = PartyAb, geometry = geometry)) + scale_fill_manual(values = aus_colours) #UPDATED CODE - previous variable assignments from past weeks winners_fix = winners_with_map auscolors = aus_colours ``` ] --- # Recall <i class="fas fa-database"></i> 2021 Federal Election Data .flex[ .w-50[ <img src="images/lecture-06/aec-map-1.png" width="432" style="display: block; margin: auto;" /> ] .w-50[ There are two sources of data: 1. Electoral boundary 2. The votes for candidates in each electorate ] ] --- # Recall <i class="fas fa-database"></i> 2021 ABS Census Data * DataPacks <i class="fas fa-download"></i> https://datapacks.censusdata.abs.gov.au/datapacks/ * GeoPackages <i class="fas fa-download"></i> https://datapacks.censusdata.abs.gov.au/geopackages/ <img src="images/lecture-07/datapack-download.png" width = "70%"/> --- class: transition # ABS Census 2021 # GeoPackages --- # GeoPackage .blockquote[ A **GeoPackage** (GPKG) is an open, non-proprietary, platform-independent and standards-based data format for geographic information system implemented as a SQLite database container. Defined by the **Open Geospatial Consortium** (OGC) with the backing of the US military and published in 2014, GeoPackage has seen widespread support from various government, commercial, and open source organizations. .right[ — Wikipedia ] ] <br> Recall: OGC also defines the WKT --- # ABS GeoPackage (2021) .info-box[ <i class="fas fa-download"></i> https://datapacks.censusdata.abs.gov.au/geopackages/ 1. 2021 2. Victoria 3. Topic: Employment and Income or Table: G17 4. GDA2020 ] * **Or use the [`strayr`](https://github.com/runapp-aus/strayr) package!** We'll use the one from the ABS website instead. .f6.overflow-scroll.h-40[ ```r # 2022 geopath_2021_G02 <- here::here("data/Geopackage_2021_G02_VIC_GDA2020/G02_VIC_GDA2020.gpkg") st_layers(geopath_2021_G02) ``` ``` ## Driver: GPKG ## Available layers: ## layer_name geometry_type features fields crs_name ## 1 G02_UCL_2021_VIC Multi Polygon 347 11 GDA2020 ## 2 G02_SUA_2021_VIC Multi Polygon 22 11 GDA2020 ## 3 G02_STE_2021_VIC Multi Polygon 1 11 GDA2020 ## 4 G02_SOSR_2021_VIC Multi Polygon 12 11 GDA2020 ## 5 G02_SOS_2021_VIC Multi Polygon 6 11 GDA2020 ## 6 G02_SED_2021_VIC Multi Polygon 90 11 GDA2020 ## 7 G02_SAL_2021_VIC Multi Polygon 2946 11 GDA2020 ## 8 G02_SA4_2021_VIC Multi Polygon 19 11 GDA2020 ## 9 G02_SA3_2021_VIC Multi Polygon 68 11 GDA2020 ## 10 G02_SA2_2021_VIC Multi Polygon 524 11 GDA2020 ## 11 G02_SA1_2021_VIC Multi Polygon 15482 11 GDA2020 ## 12 G02_POA_2021_VIC Multi Polygon 694 11 GDA2020 ## 13 G02_LGA_2021_VIC Multi Polygon 82 11 GDA2020 ## 14 G02_GCCSA_2021_VIC Multi Polygon 4 11 GDA2020 ## 15 G02_CED_2021_VIC Multi Polygon 41 11 GDA2020 ## 16 G02_RA_2021_VIC Multi Polygon 6 11 GDA2020 ``` ] --- # ABS GeoPackage (2016) .info-box[ <i class="fas fa-download"></i> https://datapacks.censusdata.abs.gov.au/geopackages/ 1. Victoria 2. Employment, Income and Unpaid Work (EIUW) 3. EIUW GeoPackage A ] * **Or use the [`strayr`](https://github.com/runapp-aus/strayr) package!** We'll use the one from the ABS website instead. .f6.overflow-scroll.h-40[ ```r geopath_2016_eiuwa <- here::here("data/Geopackage_2016_EIUWA_for_VIC/census2016_eiuwa_vic_short.gpkg") st_layers(geopath_2016_eiuwa) ``` ``` ## Driver: GPKG ## Available layers: ## layer_name geometry_type features fields crs_name ## 1 census2016_eiuwa_vic_ced_short 39 489 GDA94 ## 2 census2016_eiuwa_vic_gccsa_short 4 489 GDA94 ## 3 census2016_eiuwa_vic_lga_short 82 489 GDA94 ## 4 census2016_eiuwa_vic_poa_short 698 489 GDA94 ## 5 census2016_eiuwa_vic_ra_short 6 489 GDA94 ## 6 census2016_eiuwa_vic_sa1_short 14073 489 GDA94 ## 7 census2016_eiuwa_vic_sa2_short 464 489 GDA94 ## 8 census2016_eiuwa_vic_sa3_short 68 489 GDA94 ## 9 census2016_eiuwa_vic_sa4_short 19 489 GDA94 ## 10 census2016_eiuwa_vic_sed_short 90 489 GDA94 ## 11 census2016_eiuwa_vic_sos_short 6 489 GDA94 ## 12 census2016_eiuwa_vic_sosr_short 12 489 GDA94 ## 13 census2016_eiuwa_vic_ssc_short 2931 489 GDA94 ## 14 census2016_eiuwa_vic_ste_short 1 489 GDA94 ## 15 census2016_eiuwa_vic_sua_short 22 489 GDA94 ## 16 census2016_eiuwa_vic_ucl_short 353 489 GDA94 ``` ```r #UPDATED CODE - old variable assignments from years # geopath = geopath_2016_eiuwa ``` ] --- # The Australian Statistical Geography Standard (ASGS) .center[ <img src="images/lecture-08/acgs-structures.png" width="75%"> ] --- # The number of regions for each layer .f5[ ```r st_layers(geopath_2021_G02) %>% # make it into a data.frame first tibble(!!!.) %>% # then you can the dplyr operations dplyr::arrange(features) ``` ``` ## # A tibble: 16 × 6 ## name geomtype driver features fields crs ## <chr> <list> <chr> <dbl> <dbl> <list> ## 1 G02_STE_2021_VIC <chr [1]> GPKG 1 11 <crs> ## 2 G02_GCCSA_2021_VIC <chr [1]> GPKG 4 11 <crs> ## 3 G02_SOS_2021_VIC <chr [1]> GPKG 6 11 <crs> ## 4 G02_RA_2021_VIC <chr [1]> GPKG 6 11 <crs> ## 5 G02_SOSR_2021_VIC <chr [1]> GPKG 12 11 <crs> ## 6 G02_SA4_2021_VIC <chr [1]> GPKG 19 11 <crs> ## 7 G02_SUA_2021_VIC <chr [1]> GPKG 22 11 <crs> ## 8 G02_CED_2021_VIC <chr [1]> GPKG 41 11 <crs> ## 9 G02_SA3_2021_VIC <chr [1]> GPKG 68 11 <crs> ## 10 G02_LGA_2021_VIC <chr [1]> GPKG 82 11 <crs> ## 11 G02_SED_2021_VIC <chr [1]> GPKG 90 11 <crs> ## 12 G02_UCL_2021_VIC <chr [1]> GPKG 347 11 <crs> ## 13 G02_SA2_2021_VIC <chr [1]> GPKG 524 11 <crs> ## 14 G02_POA_2021_VIC <chr [1]> GPKG 694 11 <crs> ## 15 G02_SAL_2021_VIC <chr [1]> GPKG 2946 11 <crs> ## 16 G02_SA1_2021_VIC <chr [1]> GPKG 15482 11 <crs> ``` ] --- # <i class="fas fa-search-dollar"></i> Data in the layer .f5.overflow-scroll.h-90[ ```r vicmap_ste_G02 <- read_sf(geopath_2021_G02, layer = "G02_STE_2021_VIC") vicmap_ste_G02$geom ``` ``` ## Geometry set for 1 feature ## Geometry type: MULTIPOLYGON ## Dimension: XY ## Bounding box: xmin: 140.9619 ymin: -39.15918 xmax: 149.9762 ymax: -33.98064 ## Geodetic CRS: GDA2020 ``` ```r str(vicmap_ste_G02) ``` ``` ## sf [1 × 12] (S3: sf/tbl_df/tbl/data.frame) ## $ STE_CODE_2021 : chr "2" ## $ STE_NAME_2021 : chr "Victoria" ## $ Median_age_persons : num 38 ## $ Median_mortgage_repay_monthly: num 1859 ## $ Median_tot_prsnl_inc_weekly : num 803 ## $ Median_rent_weekly : num 370 ## $ Median_tot_fam_inc_weekly : num 2136 ## $ Average_num_psns_per_bedroom : num 0.8 ## $ Median_tot_hhd_inc_weekly : num 1759 ## $ Average_household_size : num 2.5 ## $ AREA_ALBERS_SQKM : num 227496 ## $ geom :sfc_MULTIPOLYGON of length 1; first list element: List of 157 ## ..$ :List of 1 ## .. ..$ : num [1:39, 1:2] 146 146 146 146 146 ... ## ..$ :List of 1 ## .. ..$ : num [1:25, 1:2] 146 146 146 146 146 ... ## ..$ :List of 1 ## .. ..$ : num [1:17, 1:2] 146 146 146 146 146 ... ## ..$ :List of 1 ## .. ..$ : num [1:112, 1:2] 146 146 146 146 146 ... ## ..$ :List of 1 ## .. ..$ : num [1:151, 1:2] 146 146 146 146 146 ... ## ..$ :List of 1 ## .. ..$ : num [1:18, 1:2] 146 146 146 146 146 ... ## ..$ :List of 1 ## .. ..$ : num [1:859, 1:2] 150 150 150 150 150 ... ## ..$ :List of 1 ## .. ..$ : num [1:64, 1:2] 150 150 150 150 150 ... ## ..$ :List of 1 ## .. ..$ : num [1:18, 1:2] 145 145 145 145 145 ... ## ..$ :List of 1 ## .. ..$ : num [1:1149, 1:2] 145 145 145 145 145 ... ## ..$ :List of 1 ## .. ..$ : num [1:76, 1:2] 145 145 145 145 145 ... ## ..$ :List of 1 ## .. ..$ : num [1:114, 1:2] 145 145 145 145 145 ... ## ..$ :List of 1 ## .. ..$ : num [1:34, 1:2] 145 145 145 145 145 ... ## ..$ :List of 1 ## .. ..$ : num [1:12, 1:2] 145 145 145 145 145 ... ## ..$ :List of 1 ## .. ..$ : num [1:10, 1:2] 145 145 145 145 145 ... ## ..$ :List of 1 ## .. ..$ : num [1:7, 1:2] 145 145 145 145 145 ... ## ..$ :List of 1 ## .. ..$ : num [1:1501, 1:2] 145 145 145 145 145 ... ## ..$ :List of 1 ## .. ..$ : num [1:281, 1:2] 142 142 142 142 142 ... ## ..$ :List of 1 ## .. ..$ : num [1:29, 1:2] 145 145 145 145 145 ... ## ..$ :List of 1 ## .. ..$ : num [1:16, 1:2] 145 145 145 145 145 ... ## ..$ :List of 1 ## .. ..$ : num [1:8, 1:2] 145 145 145 145 145 ... ## ..$ :List of 1 ## .. ..$ : num [1:18, 1:2] 145 145 145 145 145 ... ## ..$ :List of 1 ## .. ..$ : num [1:12, 1:2] 145 145 145 145 145 ... ## ..$ :List of 1 ## .. ..$ : num [1:12, 1:2] 145 145 145 145 145 ... ## ..$ :List of 1 ## .. ..$ : num [1:10, 1:2] 145 145 145 145 145 ... ## ..$ :List of 1 ## .. ..$ : num [1:7, 1:2] 145 145 145 145 145 ... ## ..$ :List of 1 ## .. ..$ : num [1:152979, 1:2] 145 145 145 145 145 ... ## ..$ :List of 1 ## .. ..$ : num [1:4281, 1:2] 145 145 145 145 145 ... ## ..$ :List of 1 ## .. ..$ : num [1:7592, 1:2] 147 147 147 147 147 ... ## ..$ :List of 1 ## .. ..$ : num [1:2378, 1:2] 147 147 147 147 147 ... ## ..$ :List of 1 ## .. ..$ : num [1:3789, 1:2] 147 147 147 147 147 ... ## ..$ :List of 1 ## .. ..$ : num [1:1718, 1:2] 146 146 146 146 146 ... ## ..$ :List of 1 ## .. ..$ : num [1:2093, 1:2] 147 147 147 147 147 ... ## ..$ :List of 1 ## .. ..$ : num [1:2021, 1:2] 147 147 147 147 147 ... ## ..$ :List of 1 ## .. ..$ : num [1:1138, 1:2] 147 147 147 147 147 ... ## ..$ :List of 1 ## .. ..$ : num [1:796, 1:2] 147 147 147 147 147 ... ## ..$ :List of 1 ## .. ..$ : num [1:348, 1:2] 146 146 146 146 146 ... ## ..$ :List of 1 ## .. ..$ : num [1:896, 1:2] 147 147 147 147 147 ... ## ..$ :List of 1 ## .. ..$ : num [1:1095, 1:2] 147 147 147 147 147 ... ## ..$ :List of 1 ## .. ..$ : num [1:699, 1:2] 147 147 147 147 147 ... ## ..$ :List of 1 ## .. ..$ : num [1:1431, 1:2] 147 147 147 147 147 ... ## ..$ :List of 1 ## .. ..$ : num [1:549, 1:2] 147 147 147 147 147 ... ## ..$ :List of 1 ## .. ..$ : num [1:252, 1:2] 146 146 146 146 146 ... ## ..$ :List of 1 ## .. ..$ : num [1:334, 1:2] 145 145 145 145 145 ... ## ..$ :List of 1 ## .. ..$ : num [1:219, 1:2] 146 146 146 146 146 ... ## ..$ :List of 1 ## .. ..$ : num [1:469, 1:2] 147 147 147 147 147 ... ## ..$ :List of 1 ## .. ..$ : num [1:94, 1:2] 146 146 146 146 146 ... ## ..$ :List of 1 ## .. ..$ : num [1:329, 1:2] 147 147 147 147 147 ... ## ..$ :List of 1 ## .. ..$ : num [1:375, 1:2] 147 147 147 147 147 ... ## ..$ :List of 1 ## .. ..$ : num [1:91, 1:2] 147 147 147 147 147 ... ## ..$ :List of 1 ## .. ..$ : num [1:12, 1:2] 147 147 147 147 147 ... ## ..$ :List of 1 ## .. ..$ : num [1:225, 1:2] 147 147 147 147 147 ... ## ..$ :List of 1 ## .. ..$ : num [1:142, 1:2] 146 146 146 146 146 ... ## ..$ :List of 1 ## .. ..$ : num [1:236, 1:2] 147 147 147 147 147 ... ## ..$ :List of 1 ## .. ..$ : num [1:104, 1:2] 146 146 146 146 146 ... ## ..$ :List of 1 ## .. ..$ : num [1:279, 1:2] 147 147 147 147 147 ... ## ..$ :List of 1 ## .. ..$ : num [1:274, 1:2] 147 147 147 147 147 ... ## ..$ :List of 1 ## .. ..$ : num [1:10, 1:2] 147 147 147 147 147 ... ## ..$ :List of 1 ## .. ..$ : num [1:255, 1:2] 147 147 147 147 147 ... ## ..$ :List of 1 ## .. ..$ : num [1:206, 1:2] 147 147 147 147 147 ... ## ..$ :List of 1 ## .. ..$ : num [1:224, 1:2] 147 147 147 147 147 ... ## ..$ :List of 1 ## .. ..$ : num [1:248, 1:2] 147 147 147 147 147 ... ## ..$ :List of 1 ## .. ..$ : num [1:469, 1:2] 147 147 147 147 147 ... ## ..$ :List of 1 ## .. ..$ : num [1:159, 1:2] 147 147 147 147 147 ... ## ..$ :List of 1 ## .. ..$ : num [1:311, 1:2] 147 147 147 147 147 ... ## ..$ :List of 1 ## .. ..$ : num [1:169, 1:2] 147 147 147 147 147 ... ## ..$ :List of 1 ## .. ..$ : num [1:196, 1:2] 147 147 147 147 147 ... ## ..$ :List of 1 ## .. ..$ : num [1:43, 1:2] 146 146 146 146 146 ... ## ..$ :List of 1 ## .. ..$ : num [1:15, 1:2] 147 147 147 147 147 ... ## ..$ :List of 1 ## .. ..$ : num [1:178, 1:2] 147 147 147 147 147 ... ## ..$ :List of 1 ## .. ..$ : num [1:117, 1:2] 146 146 146 146 146 ... ## ..$ :List of 1 ## .. ..$ : num [1:16, 1:2] 147 147 147 147 147 ... ## ..$ :List of 1 ## .. ..$ : num [1:192, 1:2] 147 147 147 147 147 ... ## ..$ :List of 1 ## .. ..$ : num [1:50, 1:2] 145 145 145 145 145 ... ## ..$ :List of 1 ## .. ..$ : num [1:162, 1:2] 147 147 147 147 147 ... ## ..$ :List of 1 ## .. ..$ : num [1:144, 1:2] 147 147 147 147 147 ... ## ..$ :List of 1 ## .. ..$ : num [1:128, 1:2] 147 147 147 147 147 ... ## ..$ :List of 1 ## .. ..$ : num [1:189, 1:2] 147 147 147 147 147 ... ## ..$ :List of 1 ## .. ..$ : num [1:309, 1:2] 147 147 147 147 147 ... ## ..$ :List of 1 ## .. ..$ : num [1:139, 1:2] 147 147 147 147 147 ... ## ..$ :List of 1 ## .. ..$ : num [1:139, 1:2] 147 147 147 147 147 ... ## ..$ :List of 1 ## .. ..$ : num [1:146, 1:2] 147 147 147 147 147 ... ## ..$ :List of 1 ## .. ..$ : num [1:85, 1:2] 146 146 146 146 146 ... ## ..$ :List of 1 ## .. ..$ : num [1:194, 1:2] 147 147 147 147 147 ... ## ..$ :List of 1 ## .. ..$ : num [1:99, 1:2] 146 146 146 146 146 ... ## ..$ :List of 1 ## .. ..$ : num [1:140, 1:2] 147 147 147 147 147 ... ## ..$ :List of 1 ## .. ..$ : num [1:101, 1:2] 147 147 147 147 147 ... ## ..$ :List of 1 ## .. ..$ : num [1:83, 1:2] 147 147 147 147 147 ... ## ..$ :List of 1 ## .. ..$ : num [1:100, 1:2] 147 147 147 147 147 ... ## ..$ :List of 1 ## .. ..$ : num [1:103, 1:2] 147 147 147 147 147 ... ## ..$ :List of 1 ## .. ..$ : num [1:74, 1:2] 147 147 147 147 147 ... ## ..$ :List of 1 ## .. ..$ : num [1:37, 1:2] 145 145 145 145 145 ... ## ..$ :List of 1 ## .. ..$ : num [1:91, 1:2] 147 147 147 147 147 ... ## ..$ :List of 1 ## .. ..$ : num [1:77, 1:2] 147 147 147 147 147 ... ## ..$ :List of 1 ## .. ..$ : num [1:47, 1:2] 143 143 143 143 143 ... ## ..$ :List of 1 ## .. ..$ : num [1:80, 1:2] 147 147 147 147 147 ... ## ..$ :List of 1 ## .. ..$ : num [1:127, 1:2] 147 147 147 147 147 ... ## ..$ :List of 1 ## .. ..$ : num [1:61, 1:2] 147 147 147 147 147 ... ## ..$ :List of 1 ## .. ..$ : num [1:85, 1:2] 147 147 147 147 147 ... ## .. [list output truncated] ## ..- attr(*, "class")= chr [1:3] "XY" "MULTIPOLYGON" "sfg" ## - attr(*, "sf_column")= chr "geom" ## - attr(*, "agr")= Factor w/ 3 levels "constant","aggregate",..: NA NA NA NA NA NA NA NA NA NA ... ## ..- attr(*, "names")= chr [1:11] "STE_CODE_2021" "STE_NAME_2021" "Median_age_persons" "Median_mortgage_repay_monthly" ... ``` ```r vicmap_ste = vicmap_ste_G02 ``` ] --- name: ste # State or Territory (STE) .f6[ ```r vicmap_ste_G02 <- read_sf(geopath_2021_G02, layer = "G02_STE_2021_VIC") ggplot(vicmap_ste_G02) + geom_sf(aes(geometry = geom, fill = Median_age_persons)) ``` <img src="images/lecture-06/map-ste-1.png" width="432" style="display: block; margin: auto;" /> ```r nrow(vicmap_ste) ``` ``` ## [1] 1 ``` ] --- # Breakout Session <center> .aim-box.tl.w-70[ Try it yourself time: - Download the geopackage for the 2021 census and variable G02 - Look at how that spatial data is organised - Look at the different layers What are the differences between the regionalisations? What do you notice? Want a challenge visualise the 2016 data! ] </center> --- name: gccsa # Greater Capital City Statistical Areas (GCCSA) * Each region with variable population ```r vicmap_gccsa_G02 <- read_sf(geopath_2021_G02, layer = "G02_GCCSA_2021_VIC") ggplot(vicmap_gccsa_G02) + geom_sf(aes(geometry = geom, fill = Median_age_persons)) ``` <img src="images/lecture-06/map-gccsa-1.png" width="432" style="display: block; margin: auto;" /> ```r nrow(vicmap_gccsa_G02) ``` ``` ## [1] 4 ``` --- name: sos # Section of State (SOS) * Major urban, other urban, bounded locally & rural balance ```r vicmap_sos_G02 <- read_sf(geopath_2021_G02, layer = "G02_SOS_2021_VIC") ggplot(vicmap_sos_G02) + geom_sf(aes(geometry = geom, fill = Median_age_persons)) ``` <img src="images/lecture-06/map-sos-1.png" width="432" style="display: block; margin: auto;" /> ```r nrow(vicmap_sos_G02) ``` ``` ## [1] 6 ``` --- name: ra # Remoteness Areas (RA) ```r vicmap_ra_G02 <- read_sf(geopath_2021_G02, layer = "G02_RA_2021_VIC") ggplot(vicmap_ra_G02) + geom_sf(aes(geometry = geom, fill = Median_age_persons)) ``` <img src="images/lecture-06/map-ra-1.png" width="432" style="display: block; margin: auto;" /> ```r nrow(vicmap_ra_G02) ``` ``` ## [1] 6 ``` --- name: sosr # Section of State Ranges (SOSR) ```r vicmap_sosr_G02 <- read_sf(geopath_2021_G02, layer = "G02_SOSR_2021_VIC") ggplot(vicmap_sosr_G02) + geom_sf(aes(geometry = geom, fill = Median_age_persons)) ``` <img src="images/lecture-06/map-sosr-1.png" width="432" style="display: block; margin: auto;" /> ```r nrow(vicmap_sosr_G02) ``` ``` ## [1] 12 ``` --- name: sa4 # Statistical Area Level 4 (SA4) * Each region with population of 100,000 - 500,000 ```r vicmap_sa4_G02 <- read_sf(geopath_2021_G02, layer = "G02_SA4_2021_VIC") ggplot(vicmap_sa4_G02) + geom_sf(aes(geometry = geom, fill = Median_age_persons)) ``` <img src="images/lecture-06/map-sa4-1.png" width="432" style="display: block; margin: auto;" /> ```r nrow(vicmap_sa4_G02) ``` ``` ## [1] 19 ``` --- name: sua # Significant Urban Areas (SUA) ```r vicmap_sua_G02 <- read_sf(geopath_2021_G02, layer = "G02_SUA_2021_VIC") ggplot(vicmap_sua_G02) + geom_sf(aes(geometry = geom, fill = Median_age_persons)) ``` <img src="images/lecture-06/map-sua-1.png" width="432" style="display: block; margin: auto;" /> ```r nrow(vicmap_sua_G02) ``` ``` ## [1] 22 ``` --- name: ced # Commonwealth Electoral Division (CED) ```r vicmap_ced_G02 <- read_sf(geopath_2021_G02, layer = "G02_CED_2021_VIC") ggplot(vicmap_ced_G02) + geom_sf(aes(geometry = geom, fill = Median_age_persons)) ``` <img src="images/lecture-06/map-ced-1.png" width="432" style="display: block; margin: auto;" /> ```r nrow(vicmap_ced_G02) ``` ``` ## [1] 41 ``` --- name: sa3 # Statistical Area Level 3 (SA3) * Each region with population of 30,000 - 130,000 ```r vicmap_sa3_G02 <- read_sf(geopath_2021_G02, layer = "G02_SA3_2021_VIC") ggplot(vicmap_sa3_G02) + geom_sf(aes(geometry = geom, fill = Median_age_persons)) ``` <img src="images/lecture-06/map-sa3-1.png" width="432" style="display: block; margin: auto;" /> ```r nrow(vicmap_sa3_G02) ``` ``` ## [1] 68 ``` --- name: lga # Local Government Area (LGA) ```r vicmap_lga_G02 <- read_sf(geopath_2021_G02, layer = "G02_SA3_2021_VIC") ggplot(vicmap_lga_G02) + geom_sf(aes(geometry = geom, fill = Median_age_persons)) ``` <img src="images/lecture-06/map-lga-1.png" width="432" style="display: block; margin: auto;" /> ```r nrow(vicmap_lga_G02) ``` ``` ## [1] 68 ``` --- name: sed # State Electoral Division (SED) ```r vicmap_sed_G02 <- read_sf(geopath_2021_G02, layer = "G02_SED_2021_VIC") ggplot(vicmap_sed_G02) + geom_sf(aes(geometry = geom, fill = Median_age_persons)) ``` <img src="images/lecture-06/map-sed-1.png" width="432" style="display: block; margin: auto;" /> ```r nrow(vicmap_sed_G02) ``` ``` ## [1] 90 ``` --- # Urban Centres and Localities (UCL) ```r vicmap_ucl_G02 <- read_sf(geopath_2021_G02, layer = "G02_UCL_2021_VIC") ggplot(vicmap_ucl_G02) + geom_sf(aes(geometry = geom, fill = Median_age_persons)) ``` <img src="images/lecture-06/map-ucl-1.png" width="432" style="display: block; margin: auto;" /> ```r nrow(vicmap_ucl_G02) ``` ``` ## [1] 347 ``` --- name: sa2 # Statistical Area Level 2 (SA2) * Each region with populations in the range of 3,000-25,000 ```r vicmap_sa2_G02 <- read_sf(geopath_2021_G02, layer = "G02_SA3_2021_VIC") ggplot(vicmap_sa2_G02) + geom_sf(aes(geometry = geom, fill = Median_age_persons)) ``` <img src="images/lecture-06/map-sa2-1.png" width="432" style="display: block; margin: auto;" /> ```r nrow(vicmap_sa2_G02) ``` ``` ## [1] 68 ``` --- name: poa # Postal Areas (POA) ```r vicmap_poa_G02 <- read_sf(geopath_2021_G02, layer = "G02_POA_2021_VIC") ggplot(vicmap_poa_G02) + geom_sf(aes(geometry = geom, fill = Median_age_persons)) ``` <img src="images/lecture-06/map-poa-1.png" width="432" style="display: block; margin: auto;" /> ```r nrow(vicmap_poa_G02) ``` ``` ## [1] 694 ``` --- name: ssc # State Area Localitites (SAL) (Formerly SSC) ```r vicmap_sal_G02 <- read_sf(geopath_2021_G02, layer = "G02_SAL_2021_VIC") ggplot(vicmap_sal_G02) + geom_sf(aes(geometry = geom, fill = Median_age_persons)) ``` <img src="images/lecture-06/map-ssc-1.png" width="432" style="display: block; margin: auto;" /> ```r nrow(vicmap_sal_G02) ``` ``` ## [1] 2946 ``` --- name: sa1 # Statistical Area Level 1 (SA1) * Each region with a population of range 200-800 ```r vicmap_sa1_G02 <- read_sf(geopath_2021_G02, layer = "G02_SA1_2021_VIC") ggplot(vicmap_sa1_G02) + geom_sf(aes(geometry = geom, fill = Median_age_persons)) ``` <img src="images/lecture-06/map-sa1-1.png" width="432" style="display: block; margin: auto;" /> ```r nrow(vicmap_sa1_G02) ``` ``` ## [1] 15482 ``` --- class: transition # Electorate boundary <br>vs <br>Census boundary 🎯 Estimate a median age for an electorate --- # Comparing SED 2021 and electorates divisions 2022 .f4[See [here](https://wcd.numbat.space/lectures/lecture-05.html#35) for `electoral_winners` data was.] .f6[ ```r ggplot() + geom_sf(data = vicmap_sed_G02, aes(geometry = geom, fill = Median_age_persons), alpha = 1, color = "white", size = 2) + geom_sf(data = winners_with_map, aes(geometry = geometry), fill = "transparent", color = "red", size = 2) + coord_sf(xlim = c(144.95, 145.24), ylim = c(-38.05, -37.85)) + theme_bw() ``` <img src="images/lecture-06/zoomed-map-1.png" width="576" style="display: block; margin: auto;" /> ] --- # Closer look 🔬 Hotham electorate .circle.monash-bg-black.white[1] .f5[ ```r electorate <- winners_with_map |> filter(DivisionNm == "HOTHAM") # Set projection to GDA1994 using EPSG:4283 st_crs(electorate$geometry,4283) # Transform projection from GDA1994 to GDA2020 using EPSG:7844 electorate$geometry = st_transform(electorate$geometry, 7844) sed_intersect <- vicmap_sed_G02 |> filter(st_intersects(geom, electorate$geometry, sparse = FALSE )[, 1]) ggplot() + geom_sf(data = sed_intersect, aes(geometry = geom), color = "red", fill = "transparent") + geom_sf_text(data = sed_intersect, aes(label = SED_CODE_2021, geometry = geom), color = "red") + geom_sf(data = electorate, aes(geometry = geometry), fill = "transparent") + geom_sf_text(data = electorate, aes(geometry = geometry, label = DivisionNm)) ``` ] ``` ## Coordinate Reference System: ## User input: GDA94 ## wkt: ## GEOGCRS["GDA94", ## DATUM["Geocentric Datum of Australia 1994", ## ELLIPSOID["GRS 1980",6378137,298.257222101, ## LENGTHUNIT["metre",1]]], ## PRIMEM["Greenwich",0, ## ANGLEUNIT["degree",0.0174532925199433]], ## CS[ellipsoidal,2], ## AXIS["geodetic latitude (Lat)",north, ## ORDER[1], ## ANGLEUNIT["degree",0.0174532925199433]], ## AXIS["geodetic longitude (Lon)",east, ## ORDER[2], ## ANGLEUNIT["degree",0.0174532925199433]], ## USAGE[ ## SCOPE["Horizontal component of 3D system."], ## AREA["Australia including Lord Howe Island, Macquarie Island, Ashmore and Cartier Islands, Christmas Island, Cocos (Keeling) Islands, Norfolk Island. All onshore and offshore."], ## BBOX[-60.55,93.41,-8.47,173.34]], ## ID["EPSG",4283]] ``` --- # Closer look 🔬 Hotham electorate .circle.monash-bg-black.white[1] There are 7 SED regions that intersect with Hotham electorate. <img src="images/lecture-06/district-map-plot-1.png" width="504" style="display: block; margin: auto;" /> --- # Closer look 🔬 Hotham electorate .circle.monash-bg-black.white[2] .f5[ ```r *sed_intersect2 <- sed_intersect |> mutate( * geometry = st_intersection(geom, electorate$geometry), * perc_area = 100 * st_area(geometry) / st_area(geom), perc_area = as.numeric(perc_area) * ) |> filter(perc_area > 5) ggplot(sed_intersect2, aes(geometry = geometry)) + geom_sf(data = electorate) + geom_sf_text( data = electorate, aes(label = DivisionNm) ) + geom_sf(color = "red", aes(fill = Median_age_persons)) + geom_sf_text( aes( label = glue::glue("{SED_CODE_2021} ({scales::comma(perc_area, 1)}%, {Median_age_persons})") ), color = "red" ) + theme(legend.position = "bottom") ``` ] --- # Closer look 🔬 Hotham electorate .circle.monash-bg-black.white[2] * There are 5 SED areas with at least 5% intersection with the electoral area. * **How would you characterise the median age for Hotham?** <img src="images/lecture-06/district-map2-1.png" width="432" style="display: block; margin: auto;" /> --- # Closer look 🔬 Hotham electorate .circle.monash-bg-black.white[3] .flex[ .w-40[ <img src="images/lecture-06/district-map2-1.png" width="432" style="display: block; margin: auto;" /> ] .w-60.f5[ **Strategy 1** ```r sort(sed_intersect2$Median_age_persons) ``` ``` ## [1] 35 37 37 40 41 ``` {{content}} ]] -- **Strategy 2** ```r mean(sed_intersect2$Median_age_persons) ``` ``` ## [1] 38 ``` {{content}} -- **Strategy 3** ```r weighted.mean( sed_intersect2$Median_age_persons, sed_intersect2$perc_area ) ``` ``` ## [1] 38.06118 ``` --- # Closer look 🔬 Hotham electorate .circle.monash-bg-black.white[4] .flex[ .w-50[ .f5[ ```r *sa1_intersect <- vicmap_sa1_G02 %>% filter(st_intersects(geom, electorate$geometry, sparse = FALSE )[, 1]) sa1_intersect2 <- sa1_intersect %>% mutate( geometry = st_intersection(geom, electorate$geometry), perc_area = 100 * st_area(geometry) / st_area(geom), perc_area = as.numeric(perc_area) * ) %>% filter(perc_area > 5) ggplot(sa1_intersect) + geom_sf(color = "red", aes( fill = Median_age_persons, geometry = geom)) + geom_sf(data = electorate, color = "white", size = 2, fill = "transparent", aes(geometry = geometry)) + theme(legend.position = "bottom") ``` <img src="images/lecture-06/sa1-intersect-1.png" width="432" style="display: block; margin: auto;" /> ]] .w-50[ <img src="images/lecture-06/sa1-intersect-1.png" width="432" style="display: block; margin: auto;" /> ]] --- # Closer look 🔬 Hotham electorate .circle.monash-bg-black.white[5] .flex[ .w-40[ <img src="images/lecture-06/sa1-intersect-1.png" width="432" style="display: block; margin: auto;" /> ] .w-60.f5[ **Strategy 1** ```r fivenum(sa1_intersect2$Median_age_persons) ``` ``` ## [1] 0 35 38 41 81 ``` {{content}} ]] -- **Strategy 2** ```r mean(sa1_intersect2$Median_age_persons) ``` ``` ## [1] 38.07674 ``` {{content}} -- **Strategy 3** ```r weighted.mean(sa1_intersect2$Median_age_persons, sa1_intersect2$perc_area) ``` ``` ## [1] 38.02792 ``` {{content}} -- **Strategy 4** ```r ggplot(sa1_intersect2, aes(x = Median_age_persons)) + geom_histogram(binwidth = 1) ``` <img src="images/lecture-06/sa1-region-histogram-1.png" width="432" style="display: block; margin: auto;" /> --- # Closer look 🕵️ Zero median age (Hotham 2022)[https://www.aec.gov.au/profiles/vic/hotham.htm] .flex[ .f6.w-50[ ```r sa1_intersect2 %>% filter(Median_age_persons == 0) %>% ggplot() + geom_sf() + geom_sf( data = electorate, color = "red", fill = "transparent", aes(geometry = geometry) ) ``` <img src="images/lecture-06/strange-result-1.png" width="432" style="display: block; margin: auto;" /> ] .w-50[ <center> <img src="images/lecture-08/2018-vic-hotham-detailed-map.jpg" width = "100%"/> </center> ] ] --- # Closer look 🔬 Hotham electorate .circle.monash-bg-black.white[6] .flex[ .w-50.f5[ ## Before **Strategy 1** ```r fivenum(sa1_intersect2$Median_age_persons) ``` ``` ## [1] 0 35 38 41 81 ``` **Strategy 2** ```r mean(sa1_intersect2$Median_age_persons) ``` ``` ## [1] 38.07674 ``` **Strategy 3** ```r weighted.mean(sa1_intersect2$Median_age_persons, sa1_intersect2$perc_area) ``` ``` ## [1] 38.02792 ``` ] .w-50.f5.pl3[ ## After ```r sa1_intersect3 <- sa1_intersect2 %>% filter(Median_age_persons != 0) ``` {{content}} ]] -- **Strategy 1** ```r fivenum(sa1_intersect3$Median_age_persons) ``` ``` ## [1] 19 35 38 41 81 ``` {{content}} -- **Strategy 2** ```r mean(sa1_intersect3$Median_age_persons) ``` ``` ## [1] 38.25467 ``` {{content}} -- **Strategy 3** ```r weighted.mean(sa1_intersect3$Median_age_persons, sa1_intersect3$perc_area) ``` ``` ## [1] 38.20661 ``` --- # Dorling Cartogram .flex[ .f6.w-50[ ```r sa1_intersect4 <- sa1_intersect %>% mutate(centroid = st_centroid(geom)) dorling_plot <- ggplot(sa1_intersect4) + geom_sf( data = electorate, aes(geometry = geometry), size = 4, fill = "grey60" ) + geom_sf(aes(geometry = centroid, color = Median_age_persons), size = 0.5, shape = 3 ) + scale_color_viridis_c(name = "Median age", option = "magma") ``` ] .w-50[ <img src="images/lecture-06/unnamed-chunk-17-1.png" width="432" style="display: block; margin: auto;" /> ] ] --- # Closer look 🔬 Hotham electorate .circle.monash-bg-black.white[7] .f6[ ```r sa1_intersect5 <- sa1_intersect4 %>% filter(st_intersects(centroid, electorate$geometry, sparse = FALSE)[, 1], Median_age_persons != 0) ``` **Strategy 1** ```r fivenum(sa1_intersect5$Median_age_persons) ``` ``` ## [1] 19 35 38 41 81 ``` **Strategy 2** ```r mean(sa1_intersect5$Median_age_persons) ``` ``` ## [1] 38.20706 ``` **Strategy 4** ```r ggplot(sa1_intersect5, aes(x = Median_age_persons)) + geom_histogram(binwidth = 1) ``` <img src="images/lecture-06/sa1-region-histogram2-1.png" width="432" style="display: block; margin: auto;" /> ] --- ## Summary <center> .w-90[ <div class="idea-box"> <ul> <li>There are many ways to characterise an electorate.</li> <li>Estimates of median age of an electorate is more consistent using SA1 map data than SED map data.</li> </ul> </div> ] -- .idea-box.tl.w-90[ * We looked at mapping the 2021 census boundaries and projected a summary of the census variable (i.e. median age) onto a 2022 electoral district * Discovered some of the challenges with matching two different types of data ] -- .info-box.tl.w-90[ Read [Forbes, Cook & Hyndman (2020) Spatial modelling of the two-party preferred vote in Australian federal elections: 2001–2016. *Australian & New Zealand Journal of Statisitcs*. ](https://onlinelibrary.wiley.com/doi/abs/10.1111/anzs.12292) for a more sophisticated approach to studying the census variables and election results together. ] </center> --- class: transition #### Slides updated and maintained by Dr. Kate Saunders. Slides originally developed by Dr. Emi Tanaka --- background-size: cover class: title-slide background-image: url("images/bg-01.png") <a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by-sa/4.0/88x31.png" /></a><br />This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/">Creative Commons Attribution-ShareAlike 4.0 International License</a>. .bottom_abs.width100[ Lecturer: *Kate Saunders* Department of Econometrics and Business Statistics <i class="fas fa-envelope"></i> ETC5512.Clayton-x@monash.edu <i class="fas fa-calendar-alt"></i> Week 6 <br> ]