library(tidyverse)
library(sf)
Week 5 Tutorial
Exercise 5A
= "https://results.aec.gov.au/27966/Website/Downloads/HouseDopByDivisionDownload-27966.csv"
url
<- read_csv(url, skip = 1)
election_data
= election_data |>
election_data filter(CalculationType == "Preference Count" &
== "Y" &
Elected == 0) |>
CountNumber mutate(DivisionNm = toupper(DivisionNm))
= "data/vic-july-2021-esri/E_VIC21_region.shp"
data_path
<- read_sf(here::here(data_path)) |>
vic_election_map mutate(DivisionNm = toupper(Elect_div)) |>
st_zm()
= vic_election_map |>
vic_election_map left_join(election_data, by = "DivisionNm")
<- c(
party_colors "ALP" = "#DE3533",
"GVIC" = "#10C25B",
"IND" = "#000000",
"LP" = "#0047AB",
"NP" = "#FFFF00"
)
Exercise 5B
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")
<- vic_election_map |>
crop_map st_crop(xmin = 144.8, xmax = 145.2,
ymin = -38.1, ymax = -37.6)
<- ggplot(crop_map) +
plot_vic_electorates_cropped 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
= crop_map |>
data_for_labels 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 5C
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()