# Load necessary library
library(ggplot2)
# Data setup
data <- data.frame(
Date = as.Date(c("2024-10-30", "2024-09-01", "2024-08-01", "2024-07-01", "2023-12-14", "2023-07-23",
"2023-05-31", "2021-03-13")),
ALP = c(56, 55, 55, 56, 59, 46, 61, 69.7),
LIB = c(44, 45, 45, 44, 41, 54, 39, 30.3)
)
# Convert data to long format manually
data_long <- data.frame(
Date = rep(data$Date, 2),
Party = rep(c("ALP", "LIB"), each = nrow(data)),
Vote = c(data$ALP, data$LIB)
)
# Remove rows with missing values
data_long <- data_long[!is.na(data_long$Vote), ]
# Plot
ggplot(data_long, aes(x = Date, y = Vote, color = Party)) +
geom_point() +
geom_smooth(method = "loess", se = FALSE) +
scale_color_manual(values = c("ALP" = "red", "LIB" = "blue")) +
labs(title = "2025 Western Australia State Election Two-Party-Preferred Opinion Polling",
x = "Date",
y = "Primary Vote (%)",
color = "Party") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 45, hjust = 1))