🤺 Exercise 5A

library(tidyverse)
library(sf)
url = "https://results.aec.gov.au/27966/Website/Downloads/HouseDopByDivisionDownload-27966.csv"

election_data <- read_csv(url, skip = 1)
  
election_data = election_data |>
  filter(CalculationType == "Preference Count" &
    Elected == "Y" &
    CountNumber == 0) |>
  mutate(DivisionNm = toupper(DivisionNm))
data_path = "data/vic-july-2021-esri/E_VIC21_region.shp" 

vic_election_map <- read_sf(here::here(data_path)) %>%
  mutate(DivisionNm = toupper(Elect_div))

vic_election_map = vic_election_map |>
  left_join(election_data, by = "DivisionNm")
party_colors <- c(
  "ALP" = "#DE3533",
  "GVIC" = "#10C25B",
  "IND" = "#000000",
  "LP" = "#0047AB",
  "NP" = "#FFFF00"
)
ggplot(vic_election_map) +
   geom_sf(aes(geometry = geometry, fill = PartyAb), 
                  color = "white") + 
   coord_sf(xlim = c(144.8, 145.2), ylim = c(-38.1, -37.6)) +
   scale_fill_manual(values = party_colors) + 
   ggtitle("Winners of Australian Federal Election in 2019", 
           subtitle = "Victoria")

crop_map <- vic_election_map %>% 
  st_crop(xmin = 144.8, xmax = 145.2,
          ymin = -38.1, ymax = -37.6)

plot_vic_electorates_cropped <- ggplot(crop_map) +
   geom_sf(aes(geometry = geometry, fill = PartyAb), 
                  color = "white") + 
   ggtitle("Winners of Australian Federal Election in 2019", 
           subtitle = "Victoria") +
  scale_fill_manual(values = party_colors[unique(crop_map$PartyAb)]) 

plot_vic_electorates_cropped

data_for_labels = crop_map %>% 
      filter(Elect_div %in% c("Melbourne", "Menzies", "Macnamara"))

plot_vic_electorates_cropped +
  geom_sf_label(data = data_for_labels,
    aes(label = Elect_div, geometry = geometry),
    size = 2)

🗺 Exercise 5B

data(world, package = "spData")
ggplot(world) + geom_sf()

world %>% 
  st_transform(crs = "+proj=moll") %>% 
  ggplot() + geom_sf()

world %>% 
  st_transform(crs = "+proj=laea +x_0=0 +y_0=0 +lon_0=133.78 +lat_0=-25.27") %>% 
  ggplot() + geom_sf()

Material mainted and updated by Dr. Kate Saunders. Material orginally developed by Dr. Emi Tanaka.