- 衆院選2024年福岡11区のデータ
- RPubsにて公開
データ
## 'data.frame': 15 obs. of 13 variables:
## $ 市町村 : chr "田川市" "行橋市" "豊前市" "香春町" ...
## $ JCP : num 1511 1284 459 236 215 ...
## $ RS : num 1865 2381 839 366 314 ...
## $ CDP : num 2585 5042 1722 619 540 ...
## $ DPP : num 1253 2570 744 263 189 ...
## $ JIP : num 2410 4366 1440 549 448 ...
## $ SDP : num 1289 1308 528 265 215 ...
## $ LDP : num 4272 7564 3337 1244 1237 ...
## $ NKP : num 3781 4448 1789 1085 980 ...
## $ SAN : num 632 1224 423 136 81 ...
## $ Shiki : num 2716 3651 1227 553 436 ...
## $ Takeda : num 7723 11829 5201 2286 2061 ...
## $ Murakami: num 9294 14927 4988 1942 1736 ...
1. symbiplot,ca
# ca::ca()で分析を実行
res.ca_greenacre <- ca(data)
# ca::plot()でグラフを作成
# こちらはbase R graphicsを使用するため、ggplot2のテーマは適用されません
plot(res.ca_greenacre,
map = "symbiplot",
main = "Symbiplot (Symmetric Biplot)")

2. symmetric,ca
# ca::ca()で分析を実行
res.ca_greenacre <- ca(data)
# ca::plot()でグラフを作成
# こちらはbase R graphicsを使用するため、ggplot2のテーマは適用されません
plot(res.ca_greenacre,
map = "symmetric",
main = "Symmetric")

3. rowprincipal,ca
# ca::ca()で分析を実行
res.ca_greenacre <- ca(data)
# ca::plot()でグラフを作成
# こちらはbase R graphicsを使用するため、ggplot2のテーマは適用されません
plot(res.ca_greenacre,
map = "rowprincipal",
main = "rowprincipal")

# pty="s"の設定
par(pty="s",family= "HiraKakuProN-W3")
plot(res.ca_greenacre,map="rowprincipal", main="rowprincipal")

グラフの比較
# グラフの比較(横並び表示)
# 必要パッケージの読み込み
library(ca)
library(factoextra)
library(ggplot2)
library(patchwork) # グラフ連結用
# 対応分析の実行
res.ca <- ca(data)
# 1. Symmetric Map
# 行同士・列同士の距離(類似性)の解釈を優先
p1 <- fviz_ca_biplot(res.ca, map = "symmetric", repel = TRUE) +
coord_fixed() + # アスペクト比を1:1に固定
labs(title = "Symmetric Map",
subtitle = "行・列それぞれの内部比較に最適") +
theme_minimal(base_family="HiraKakuProN-W3") +
theme(plot.title = element_text(hjust = 0.5),
plot.subtitle = element_text(hjust = 0.5))
# 2. Symbiplot
# 行と列の間の「関連性」の解釈を優先
p2 <- fviz_ca_biplot(res.ca, map = "symbiplot", repel = TRUE) +
coord_fixed() + # アスペクト比を1:1に固定
labs(title = "Symbiplot",
subtitle = "行と列の相互作用の比較に最適") +
theme_minimal(base_family="HiraKakuProN-W3") +
theme(plot.title = element_text(hjust = 0.5),
plot.subtitle = element_text(hjust = 0.5))
# 【修正箇所】patchworkを使って横に並べる
# + 演算子で連結し、plot_layoutでレイアウトを指定
combined_plot <- p1 + p2 +
plot_layout(ncol = 2) +
plot_annotation(title = "対応分析スケーリングの比較",
theme = theme(plot.title = element_text(size = 16,
hjust = 0.5,
family = "HiraKakuProN-W3")))
# 表示
combined_plot

p1

p2
