|
library(ggplot2) |
|
|
|
sf <- 2 |
|
width <- 600 * sf |
|
height <- 335 * sf |
|
|
|
options(vsc.dev.args = list(width = width, height = height, res = 72 * sf)) |
|
|
|
# CDU/CSU |
|
# https://polymarket.com/event/cducsu-of-vote-in-german-election-2-brackets |
|
data <- data.frame( |
|
range = c("<26%", "26-28%", "28-30%", "30-32%", "32-34%", ">34%"), |
|
midpoint = c(25, 27, 29, 31, 33, 35), # Midpoints of the ranges |
|
percentage = c(0.02, 0.08, 0.38, 0.42, 0.12, 0.01) # Given percentages as fractions |
|
) |
|
# Calculating the weighted average |
|
union <- sum(data$percentage * data$midpoint) / sum(data$percentage) |
|
|
|
# AfD |
|
# https://polymarket.com/event/afd-of-vote-in-german-election-2-brackets |
|
data <- data.frame( |
|
range = c("<20%", "20-22%", "22-24%", "24-26%", ">26%"), |
|
midpoint = c(19, 21, 23, 25, 27), # Estimated midpoints |
|
percentage = c(0.22, 0.41, 0.25, 0.07, 0.07) # Given percentages |
|
) |
|
# Calculating the weighted average |
|
afd <- sum(data$percentage * data$midpoint) / sum(data$percentage) |
|
|
|
# SPD |
|
# https://polymarket.com/event/spd-of-vote-in-german-election |
|
data <- data.frame( |
|
range = c("<10%", "10-15%", "15-20%", "20-25%", "25-30%", ">30%"), |
|
midpoint = c(5, 12.5, 17.5, 22.5, 27.5, 35), # Midpoints of the ranges |
|
percentage = c(0.03, 0.44, 0.5, 0.2, 0.005, 0.005) # Given percentages as fractions |
|
) |
|
# Calculating the weighted average |
|
spd <- sum(data$percentage * data$midpoint) / sum(data$percentage) |
|
|
|
data <- data.frame( |
|
Partei = c("CDU/CSU", "AfD", "SPD"), |
|
Stimmenanteil = c(union, afd, spd) |
|
) |
|
|
|
data$Partei <- factor(data$Partei, levels = c("CDU/CSU", "AfD", "SPD")) |
|
|
|
# Create the bar chart |
|
ggplot(data, aes(x = Partei, y = Stimmenanteil, fill = Partei)) + |
|
geom_bar(stat = "identity") + |
|
geom_text(aes(label = sprintf("%.1f%%", Stimmenanteil)), |
|
vjust = -0.5, size = 4 |
|
) + |
|
scale_fill_manual(values = c("CDU/CSU" = "black", "AfD" = "blue", "SPD" = "red")) + |
|
labs( |
|
title = "Wettquoten implizierter Stimmenanteil nach Partei [Polymarket]", |
|
x = "Partei", |
|
y = "Stimmenanteil" |
|
) + |
|
theme_minimal() + |
|
theme(legend.position = "none") |