Greenacre's Symbiplot
# [Greenacre's Symbiplot]
```{r}
#####################################
### symbiplot(Greenacre)
### MST用の距離計算:主座標を使用
### 行と列の同時表示
#####################################
# 必要パッケージの読み込み
if (!require("ca")) install.packages("ca")
if (!require("ape")) install.packages("ape")
if (!require("ggrepel")) install.packages("ggrepel")
library(ca)
library(ape)
library(ggplot2)
library(ggrepel)
# 1. データの読み込み
voting_data <- read.csv("data11ku_PC.csv", row.names = 1)
counts <- voting_data[, 2:ncol(voting_data)]
# 2. 対応分析 (CA) の実行
res_ca <- ca(counts)
# 3. Symbiplot用の座標計算 (特異値の平方根を掛ける)
# の注釈に基づき、sqrt(sv) を適用
sv_sqrt <- diag(sqrt(res_ca$sv))
rows_coord <- as.data.frame(res_ca$rowcoord %*% sv_sqrt)
cols_coord <- as.data.frame(res_ca$colcoord %*% sv_sqrt)
colnames(rows_coord) <- c("Dim1", "Dim2")
rows_coord$Name <- rownames(rows_coord)
rows_coord$Group <- "City"
colnames(cols_coord) <- c("Dim1", "Dim2")
cols_coord$Name <- colnames(counts)
cols_coord$Group <- "Party/Candidate"
# --- 修正版 4. 最小全域木 (MST) の計算 ---
# A. MST用の距離計算:主座標 (Principal Coordinates) を使用
# これにより、元の分割表のカイ二乗距離が保存される
full_principal_coords <- res_ca$colcoord %*% diag(res_ca$sv) # sqrtなしの特異値を掛ける
party_dist_chi2 <- dist(full_principal_coords)
st_tree <- mst(party_dist_chi2)
# B. 可視化用の座標:Symbiplot (Symmetric Biplot) を使用
# ステップ3で作成した cols_coord (sqrt使用) をそのまま描画に使う
edges <- which(as.matrix(st_tree) == 1, arr.ind = TRUE)
edges <- edges[edges[,1] < edges[,2], ]
edge_df <- data.frame(
x = cols_coord$Dim1[edges[,1]], y = cols_coord$Dim2[edges[,1]],
xend = cols_coord$Dim1[edges[,2]], yend = cols_coord$Dim2[edges[,2]]
)
# 5. 可視化
ggplot() +
# MSTの点線 (政党・候補者間)
geom_segment(data = edge_df, aes(x=x, y=y, xend=xend, yend=yend),
color = "gray60", linetype = "dotted", linewidth = 0.5) +
# 自治体のプロット (青色・透過) [cite: 148, 149]
geom_point(data = rows_coord, aes(x=Dim1, y=Dim2), color = "blue", alpha = 0.3, size = 1.5) +
geom_text_repel(data = rows_coord, aes(x=Dim1, y=Dim2, label = Name),
color = "blue", size = 2.5, alpha = 0.6, family="HiraKakuProN-W3") +
# 政党・候補者のプロット (赤色・太字) [cite: 154, 155]
geom_point(data = cols_coord, aes(x=Dim1, y=Dim2), color = "red", size = 3) +
geom_text_repel(data = cols_coord, aes(x=Dim1, y=Dim2, label = Name),
color = "red", size = 3.5, fontface = "bold", family="HiraKakuProN-W3",
box.padding = 0.5, max.overlaps = Inf) +
# 原点補助線 [cite: 158, 159]
geom_vline(xintercept = 0, linetype = "dashed", color = "gray80") +
geom_hline(yintercept = 0, linetype = "dashed", color = "gray80") +
# テーマ設定を適用
theme_minimal(base_family="HiraKakuProN-W3") +
coord_fixed() + # 距離構造を正しく保つために必須
labs(title = "Greenacre's Symmetric Biplot (Symbiplot) with MST",
subtitle = "Scaling: Standard Coordinates * sqrt(Singular Values)",
x = paste0("Dimension 1 (", round((res_ca$sv[1]^2/sum(res_ca$sv^2))*100, 1), "%)"),
y = paste0("Dimension 2 (", round((res_ca$sv[2]^2/sum(res_ca$sv^2))*100, 1), "%)"))
```
| 固定リンク
「分析メモ」カテゴリの記事
- 高市内閣の支持・不支持の理由の推移:NHK世論調査(2026.10.05)
- 「左右対立(という戦略)」の失敗だけで説明できるのか――2026年衆議院議員選挙について(2026.06.24)
- 「リベラル」、「伝統保守」というクラスターに注目して、そのネーミングの問題点、実体化して捉えることの妥当性について検討する(2026.06.19)
- 自民党支持者の多数派は「新自由主義右翼」(橋本健二氏)か?(2026.06.15)
- 格差に対する意識と流動性に対する意識が政党支持とどのように関係しているか(2026.06.14)