-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
7,975 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
--- | ||
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: false | ||
library(tidyverse) | ||
library(rvest) | ||
library(httr) | ||
library(sf) | ||
library(geogrid) | ||
sf_use_s2(FALSE) | ||
precinct_sf <- st_read("data/2020_21_elec_253.json") | ||
sido_sf <- precinct_sf |> | ||
# filter(SGG_1 == "부산") |> | ||
calculate_grid(grid_type="hexagonal", learning_rate = 0.05, seed=20) | ||
plot(sido_sf) | ||
sido_hex <- assign_polygons(precinct_sf, sido_sf) | ||
``` | ||
|
||
```{r} | ||
# sido_hex |> | ||
# st_write("data/precinct_21.geojson") | ||
sido_hex <- | ||
st_read("data/precinct_21.geojson") | ||
sido_hex |> | ||
st_geometry() |> | ||
plot() | ||
``` | ||
|
||
# 시도 경계 | ||
|
||
```{r} | ||
sido_boundary_hex <- sido_hex |> | ||
# ungroup() |> | ||
group_by(SGG_1) |> | ||
summarise(geometry = st_union(geometry)) | ||
sido_boundary_hex |> | ||
ggplot() + | ||
geom_sf(aes(geometry = geometry, fill = SGG_1)) | ||
``` | ||
|
||
|
||
# SVG to geojson | ||
|
||
```{r} | ||
svg_sf <- st_read("data/precinct_21/cartogram.geojson") | ||
svg_sf |> | ||
plot() | ||
svg_shp <- st_read("data/precinct_21/2020_South_Korean_legislative_election_Results_Cartogram-polygon.shp") | ||
svg_sf |> | ||
plot() | ||
``` | ||
|
||
|
||
# svg magick | ||
|
||
```{r} | ||
library(magick) | ||
carto <- image_read("data/precinct_21/cartogram.svg") | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"type": "FeatureCollection", | ||
"features": [] | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
data/precinct_21/2020_South_Korean_legislative_election_Results_Cartogram-polygon.cpg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
UTF-8 |
Binary file added
BIN
+21.3 KB
data/precinct_21/2020_South_Korean_legislative_election_Results_Cartogram-polygon.dbf
Binary file not shown.
1 change: 1 addition & 0 deletions
1
data/precinct_21/2020_South_Korean_legislative_election_Results_Cartogram-polygon.prj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]] |
Binary file added
BIN
+51.6 KB
data/precinct_21/2020_South_Korean_legislative_election_Results_Cartogram-polygon.shp
Binary file not shown.
Binary file added
BIN
+2.2 KB
data/precinct_21/2020_South_Korean_legislative_election_Results_Cartogram-polygon.shx
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.