-
Notifications
You must be signed in to change notification settings - Fork 0
/
VoiceReferendum.R
30 lines (25 loc) · 985 Bytes
/
VoiceReferendum.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
library(dplyr)
library(here)
library(sf)
library(RColorBrewer)
library(leaflet)
library(ggplot2)
library(maps)
library(sp)
library(mapview)
library(tmap)
tmap_options(check.and.fix = TRUE)
electorates <- st_read(here::here('Aus2021/2021_ELB_Region.shp'))
votesall <- read.csv(here::here('2022Data.csv')) %>% filter(PartyNm != "Informal")
votes <- votesall %>% filter(PartyAb == "GRN")
votes <- votes %>% select(DivisionNm,TotalVotes)
electorates <- electorates %>% mutate(Percent=0)
for (i in 1:nrow(electorates)){
divall <- votesall %>% filter(DivisionNm == electorates$Elect_div[i])
vote <- votes %>% filter(DivisionNm == electorates$Elect_div[i])
electorates$Percent[i] <- vote$TotalVotes[1]/(sum(divall$TotalVotes))*100
}
tm_shape(electorates) + tm_polygons("Percent", style="cont", title="Greens Primary", id = "Elect_div", palette = rev(hcl.colors(8,"Greens"))) #+ tm_text("Elect_div")
tmap_mode("view")
tmap_last()
tmap_save(filename = here::here("Greens2022.html"))