This article explores the split_total
and split_electorate
datasets.
Split Voting
The split_total
and split_electorate
datasets contains the number of voters who cast their party vote for a
different party to their candidate vote at the national level, by party.
This dataset only has election years 2005 through to 2023 due to there
not being split-ticket voting data available for previous years.
Upload data
View the shape of data frame.
df <- scgUtils::get_data("split_total")
# or
# df <- scgUtils::get_data("split_electorate")
Prepare Sankey
Prepare sankey data.
# Filter 2023 election data only
<- df[df$Election == 2023, ]
df
# If electoral-level dataset is used, also filter by Electorate
# df <- df[df$Election == 2023 & df$Electorate == "Auckland Central", ]
# Rename unsuccessful minor parties into "Other" category
<- update_names(df, nameCol = "List_Party")
df <- update_names(df, nameCol = "Electorate_Party")
df
<- df %>%
df # Get sum of votes by flow
group_by(List_Party, Electorate_Party) %>%
summarise(Vote = round(sum(Votes)), .groups = 'drop') %>%
ungroup() %>%
# Get percent of party vote going to candidate vote
group_by(List_Party) %>%
mutate(Percent = round(Vote/sum(Vote)*100,2) %>%
ungroup()
head(df)
List_Party | Electorate_Party | Vote | Percent |
---|---|---|---|
ACT Party | ACT Party | 68692 | 28.46 |
ACT Party | Green Party | 2095 | 0.87 |
ACT Party | Informal | 1356 | 0.56 |
ACT Party | Labour Party | 7715 | 3.20 |
ACT Party | Maori Party | 715 | 0.30 |
ACT Party | NZ First | 3106 | 1.29 |
Plot
Using the scgUtils
package, create sankey to visualise
the split vote from the candidate vote (left) to the party vote (right).
Use the colour_prep
function from the same package to match
the party colours to the correct political party.
scgUtils::plot_sankey(
data = df,
source = "List_Party", # left side of sankey
target = "Electorate_Party", # right side of sankey
value = "Vote",
colours = scgUtils::colour_prep(df, c("List_Party","Electorate_Party"), pal_name = "polNZ"),
width = 900, # reduce width from default of 1200
height = 700, # reduce height from default of 800
shiftLabel = 8 # manually shift labels to outside of plot if odd number of parties on each side
) # %>%
# save from viewer to html
# htmlwidgets::saveWidget(file="sankey_2023.html", selfcontained = TRUE)
NB. Percentage and votes within tooltip on nodes do not exactly equal
the party_vote
or candidate_vote
of each party
due to rounding.