From 8ffe13d9d98daff38d94e531db272128c070da72 Mon Sep 17 00:00:00 2001 From: Kwangchun Lee Date: Thu, 16 Nov 2023 13:07:31 +0900 Subject: [PATCH 1/3] =?UTF-8?q?start=20=EB=B9=84=EB=A1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _quarto.yml | 2 + proportion_member.qmd | 122 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 124 insertions(+) create mode 100644 proportion_member.qmd diff --git a/_quarto.yml b/_quarto.yml index 1acb3e4..5f5d5e2 100644 --- a/_quarto.yml +++ b/_quarto.yml @@ -130,6 +130,8 @@ website: text: "투개표 API" - href: single_member.qmd text: "양당과 소선구제" + - href: proportion_member.qmd + text: "비례 국회의원" format: html: diff --git a/proportion_member.qmd b/proportion_member.qmd new file mode 100644 index 0000000..a0f4ed1 --- /dev/null +++ b/proportion_member.qmd @@ -0,0 +1,122 @@ +--- +title: "지도제작 대회" +subtitle: "비례국회의원" +description: | + 비례국회의원에 대해서 살펴보자. +author: + - name: 이광춘 + url: https://www.linkedin.com/in/kwangchunlee/ + affiliation: 한국 R 사용자회 + affiliation-url: https://github.com/bit2r +title-block-banner: true +format: + html: + theme: flatly + code-fold: true + code-overflow: wrap + toc: true + toc-depth: 3 + toc-title: 목차 + number-sections: true + highlight-style: github + self-contained: false + default-image-extension: jpg +filters: + - lightbox +lightbox: auto +link-citations: true +knitr: + opts_chunk: + eval: true + message: false + warning: false + collapse: true + comment: "#>" + R.options: + knitr.graphics.auto_pdf: true +editor_options: + chunk_output_type: console +--- + +```{r} +#| include: false +library(tidyverse) +library(rvest) +library(httr) +library(sf) +library(geogrid) +``` + + +# 데이터셋 + +```{r} +#| eval: true +library(tidyverse) +library(rvest) +library(httr) +library(sf) +library(geogrid) + +mp_raw <- read_rds("data/total_elected_tbl.rds") + +prop_tbl <- mp_raw |> + filter(sgTypecode == "7") |> + select(result) |> + unnest(result) |> + mutate(정당 = case_when(jdName %in% c("한나라당", "새누리당", "자유한국당", + "미래통합당", "국민의힘", "미래한국당") ~ "국민의힘", + jdName %in% c("새정치국민회의", "열린우리당", "통합민주당", + "민주통합당", "더불어민주당", "더불어시민당") ~ "민주당", + TRUE ~ "그외정당")) |> + + count(sgId, 정당) + +``` + + +# 분석 + +## 표 + +```{r} +library(gt) + +prop_tbl |> + pivot_wider(names_from = 정당, values_from = n) |> + mutate(소계 = 국민의힘 + 그외정당 + 민주당) |> + select(선거=sgId, 민주당, 국민의힘, 그외정당, 소계) |> + gt() |> + grand_summary_rows( + columns = c(민주당, 국민의힘, 그외정당), + fns = list( + 최소 ~ min(.), + 최대 ~ max(.), + 평균 ~ mean(.) + ), + fmt = ~ fmt_integer(.), + side = "top" + ) |> + cols_align(columns = everything(), "center") +``` + +## 그래프 + +```{r} +percent_tbl <- prop_tbl |> + group_by(sgId) |> + summarise(비율 = n / sum(n)) |> + ungroup() + +prop_tbl |> + bind_cols(percent_tbl |> select(비율)) |> + ggplot(aes(x = sgId, y = 비율, color = 정당, group = 정당)) + + geom_line() + + geom_point() + + scale_color_manual(values = c("국민의힘" = "red", + "민주당" = "blue", + "기타정당" = "gray30")) + + scale_y_continuous(labels = scales::percent) +``` + + From f03b24c87a33f3c1029a5c424b85164d3f3bfbc6 Mon Sep 17 00:00:00 2001 From: Kwangchun Lee Date: Thu, 16 Nov 2023 13:53:46 +0900 Subject: [PATCH 2/3] =?UTF-8?q?=EB=B9=84=EB=A1=80=EB=B6=84=EC=84=9D=20?= =?UTF-8?q?=EC=8B=9C=EC=9E=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- proportion_member.qmd | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/proportion_member.qmd b/proportion_member.qmd index a0f4ed1..801145f 100644 --- a/proportion_member.qmd +++ b/proportion_member.qmd @@ -115,8 +115,10 @@ prop_tbl |> geom_point() + scale_color_manual(values = c("국민의힘" = "red", "민주당" = "blue", - "기타정당" = "gray30")) + - scale_y_continuous(labels = scales::percent) + "그외정당" = "gray30")) + + scale_y_continuous(labels = scales::percent) + + theme_minimal() + + theme(legend.position = "top") ``` From 2f52be317cc440bd261d8837973cf35e48854eb2 Mon Sep 17 00:00:00 2001 From: Kwangchun Lee Date: Tue, 21 Nov 2023 17:10:55 +0900 Subject: [PATCH 3/3] start best matches --- _quarto.yml | 3 ++ best_matches.qmd | 89 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 best_matches.qmd diff --git a/_quarto.yml b/_quarto.yml index 5f5d5e2..c30e20c 100644 --- a/_quarto.yml +++ b/_quarto.yml @@ -132,6 +132,9 @@ website: text: "양당과 소선구제" - href: proportion_member.qmd text: "비례 국회의원" + - href: best_matches.qmd + text: "최고 관심 격돌" + format: html: diff --git a/best_matches.qmd b/best_matches.qmd new file mode 100644 index 0000000..48eef51 --- /dev/null +++ b/best_matches.qmd @@ -0,0 +1,89 @@ +--- +title: "지도제작 대회" +subtitle: "최고 관심 격돌" +description: | + 최고 관심 격돌 선거전을 살펴보자. +author: + - name: 이광춘 + url: https://www.linkedin.com/in/kwangchunlee/ + affiliation: 한국 R 사용자회 + affiliation-url: https://github.com/bit2r +title-block-banner: true +format: + html: + theme: flatly + code-fold: true + code-overflow: wrap + toc: true + toc-depth: 3 + toc-title: 목차 + number-sections: true + highlight-style: github + self-contained: false + default-image-extension: jpg +filters: + - lightbox +lightbox: auto +link-citations: true +knitr: + opts_chunk: + eval: true + message: false + warning: false + collapse: true + comment: "#>" + R.options: + knitr.graphics.auto_pdf: true +editor_options: + chunk_output_type: console +--- + +```{r} +#| include: false +library(tidyverse) +library(rvest) +library(httr) +library(sf) +library(geogrid) +``` + + +# 최고의 빅매치 + + +- 제18대 (2008년) 정몽준 vs 정동영 + - [정몽준-정동영 동작을 맞붙나](https://www.hani.co.kr/arti/politics/politics_general/275957.html) +- 제18대 (2008년) 노회찬 vs 홍정욱 + - [노회찬(강북좌파), 홍정욱(강남우파)에 근소한 차로 우위](https://www.hani.co.kr/arti/politics/assembly/278356.html) +- 제19대 (2012년) 이재오 vs 천호선 + - ["이재오 살리고 MB심판 하자고?", 서울 은평을, 새누리 이재오 vs 통합진보 천호선](https://www.pressian.com/pages/articles/63595) +- 제19대 (2012년) 문재인 vs 손수조 + - [부산 사상 손수조·문재인](https://m.khan.co.kr/politics/election/article/201204082255145#c2b) +- 제20대 (2016년) 안철수 vs 이준석 + - ['노원 목장'의 결투? 안철수-이준석, 총선 전운](https://www.asiae.co.kr/article/2023031010175976658) +- 제20대 (2016년) 정세균 vs 오세훈 + - [정세균 對 오세훈 ‘종로 혈투’…국민의 선택은?](http://sisa-news.com/news/article.html?no=103290) +- 제21대 (2020년) 이낙연 vs 황교안 + - [이낙연-황교안, 정치1번지 종로서 맞붙는다](https://www.ccnnews.co.kr/news/articleView.html?idxno=170838) +- 제21대 (2020년) 김용민 vs 주광덕 + - [남양주병… '조국 대전' 이슈로 격돌](https://www.yna.co.kr/view/AKR20200313115600060) + + +```{r} +library(tidyverse) + +tribble(~"선거", ~"선거구", ~"유권자", ~"투표수", ~"계", ~"정당", ~"후보", ~"득표수", + "제18대", "동작을", "154,470", "87,793", "87,332", "민주당", "정동영", "36,251", + "제18대", "동작을", "154,470", "87,793", "87,332", "국민의힘", "정몽준", "47,521", + "제18대", "노원병", "158,354", "80,732", "80,170 ", "민주당", "김성환", "13,036 ", + "제18대", "노원병", "158,354", "80,732", "80,170 ", "국민의힘", "홍정욱", "34,554", + "제18대", "노원병", "158,354", "80,732", "80,170 ", "정의당", "노회찬", "32,111", + "제20대", "노원병", "159,717", "103,710", "103,054", "국민의힘", "이준석", "32,285", + "제20대", "노원병", "159,717", "103,710", "103,054", "국민의당", "안철수", "53,930", + "제21대", "종로구", "134,516", "95,239", "94,038", "민주당", "이낙연", "54,902", + "제21대", "종로구", "134,516", "95,239", "94,038", "국민의당", "황교안", "37,594" + ) +``` + + +