絶対得票数では,自公維の減少分-944万票と公共の減少分-195万票から,全体の減少分を除いた-852万票分を,国民が+357万票,れいわが+159万票の計+516万票,保守と参政の計で+301万票と分けあった計算になっている。立憲はわずか6万票増なので,有権者の票が立憲に向かったわけではなく,自民と維新の減少のあおりで小選挙区の当選数が増えたにすぎない。
using CairoMakie
# データの準備
# populations = [93, 457, 608, 874, 1102, 1038, 1168, 595]
populations = [219, 1277, 1317, 1637, 1828, 1484, 1608, 1290]
total_population = sum(populations)
support_rates = [
[0.294, 0.008, 0.017, 0.110, 0.025, 0.034, 0.080, 0.072, 0.038, 0.021, 0.008, 0.294], # 10代
[0.321, 0.007, 0.018, 0.072, 0.021, 0.036, 0.093, 0.054, 0.036, 0.018, 0.004, 0.321], # 20代
[0.272, 0.009, 0.023, 0.097, 0.028, 0.055, 0.097, 0.069, 0.051, 0.023, 0.005, 0.272], # 30代
[0.236, 0.011, 0.027, 0.128, 0.037, 0.064, 0.075, 0.096, 0.064, 0.021, 0.005, 0.236], # 40代
[0.205, 0.018, 0.030, 0.151, 0.042, 0.060, 0.060, 0.133, 0.060, 0.030, 0.006, 0.205], # 50代
[0.161, 0.014, 0.028, 0.182, 0.070, 0.056, 0.049, 0.182, 0.042, 0.042, 0.014, 0.161], # 60代
[0.148, 0.015, 0.015, 0.218, 0.065, 0.051, 0.036, 0.211, 0.022, 0.058, 0.015, 0.148], # 70代
[0.285, 0.005, 0.005, 0.171, 0.042, 0.028, 0.014, 0.115, 0.005, 0.037, 0.009, 0.285] # 80代
]
colors = ["#AAAAAA", "#777777", "#FC9F05", "#FF0000", "#F9EA09", "#00FF00", "#2242D2", "#06EAFC", "#FA69FF", "#DD0000", "#777777", "#AAAAAA"]
age_labels = ["18-", "20-", "30-", "40-", "50-", "60-", "70-", "80-"]
# プロットの作成
fig = Figure(size=(800, 600))
ax = Axis(fig[1, 1], ylabel="人口割合", xlabel="投票率")
current_y = 0.0
for (i, pop) in enumerate(populations)
segment_height = pop / total_population
rates = support_rates[i]
current_x = 0.0
for (j, rate) in enumerate(rates)
poly!(ax, [current_x, current_x+rate, current_x+rate, current_x],
[current_y, current_y, current_y+segment_height, current_y+segment_height],
color=colors[j])
current_x += rate
end
# 年代ラベルを追加
text!(ax, -0.05, current_y + segment_height/2, text=age_labels[i],
align=(:right, :center), fontsize=14)
current_y += segment_height
end
# 軸の設定
ax.yticks = (collect(0:0.2:1), ["0%", "20%", "40%", "60%", "80%", "100%"])
ax.xticks = (collect(0:0.2:1), ["0%", "20%", "40%", "60%", "80%", "100%"])
# 凡例の追加
elements = [PolyElement(polycolor = c) for c in colors]
Legend(fig[1, 2], elements, ["--", "保守", "参政", "自民", "公明", "維新", "国民","立憲", "れいわ", "共産", "社民", "--"],
"政党", tellheight=false, tellwidth=true)
# タイトルの追加
Label(fig[0, :], "年代別投票率", fontsize = 24)
# グラフの表示
display(fig)