-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLeftRight.qmd
More file actions
140 lines (117 loc) · 3.53 KB
/
LeftRight.qmd
File metadata and controls
140 lines (117 loc) · 3.53 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
---
title: "Left Right Differences of Australian Parties"
subtitle: "2022 Federal Election Results"
author: "Christian Klettner"
format: html
editor: visual
execute:
echo: false
message: false
warning: false
---
```{ojs}
Plot = import("https://cdn.jsdelivr.net/npm/@observablehq/plot/+esm")
```
```{r}
library(tidyverse)
rightness <- function(x) {
right <- c("ALP"=1, "UAPP"=3, "ON"=3, "LP"=2,
"GRN"=0, "LDP"=2, "CYA"=3, "AJP"= 0,
"GVIC"=0, "LNP"=2,"NP"=2, "GAP"=3)
right <- c("ALP"=1, "UAPP"=3, "ON"=3,
"GVIC"=0, "GRN"=0,
"LP"=2, "LNP"=2, "NP"=2)
ifelse(x %in% names(right), right[x], NA) }
data <- read_csv("data/prefflows2022.csv")
```
# Australia Preferential Voting Distribution
Left-right is scored as:
- `0` points: GRN & GVIC
- `1` points: ALP
- `2` points: LP, LNP & NP
- `3` points: UAPP, ON
Other parties and candidates are not scored. The score values therefore have no inherent meaning and the outcome should be interpreted as a relative rank.
Electorates and parties are scored based on the weighted average preference counts.
## Electoral ratings
```{r}
electorates <- data |>
filter(CountNum==0) |>
mutate(Right=rightness(PartyAb)) |>
filter(!is.na(Right)) |>
summarise(Right= sum(Right*Votes)/sum(Votes),
Votes = sum(Votes),
.by=c("StateAb", "DivisionId", "DivisionNm")) |>
inner_join(data |>
filter(CountNum==max(CountNum),
.by="DivisionNm") |>
filter(Votes==max(Votes),
.by="DivisionNm") |>
select(DivisionId, PartyAb, PartyNm),
by="DivisionId")
ojs_define(elect = electorates)
```
```{ojs}
//| fig-cap: Left-Right Distribution of Electorates based on First Preferences
Plot.plot({
height: 300,
color: { legend: true },
r: { range: [0, 8] },
x: { axis: null, clip: false },
y: { axis: null },
clip: false,
margin: 30,
marks: [
Plot.ruleY([0]),
Plot.dotX(transpose(elect),
Plot.dodgeY({x: "Right",
tip: true,
title: d => d.StateAb + "\n" + d.DivisionNm,
fill: "PartyAb", //"StateAb",
r: "Votes",
anchor: "middle"
}))
]
})
```
## Candidates
```{r}
candidates <- data |>
filter(CountNum > 0) |>
filter(PrefFlow > 0) |>
mutate(Right = rightness(PartyAb)) |>
filter(!is.na(Right)) |>
summarise(Right = sum(Right*PrefFlow)/sum(PrefFlow),
Votes = sum(PrefFlow),
.by="FromPartyAb") |>
inner_join(
data |>
distinct(PartyAb, PartyNm) |>
mutate(PartyNm = str_remove(PartyNm, "\\s\\(.+\\)")) |>
summarise(PartyNm = head(PartyNm,1), .by="PartyAb"),
by=c("FromPartyAb"="PartyAb")
)
ojs_define(candi=candidates)
```
```{ojs}
//| fig-cap: Left-Right Distribution of Minor Parties and Independents based on Left-Right Preference Redistribution
Plot.plot({
height: 300,
color: { legend: false, scheme: "BuRd", type: "sequential", reverse: true },
r: { range: [0, 50] },
x: { axis: null, clip: false },
y: { axis: null },
//clip: false,
margin: 30,
marks: [
Plot.ruleY([0]),
Plot.dotX(transpose(candi).filter(d => !["ALP", "LP", "LNP", "NP"].includes(d.FromPartyAb)),
Plot.dodgeY({x: "Right",
tip: true,
title: d => d.FromPartyAb + "\n" + d.PartyNm,
fill: "Right",
r: "Votes",
anchor: "middle"
}))
]
})
```