국가 코드

R-Blogger · 블로그·해설 · 2025-11-22

R-Blogger블로그·해설한국어2025-11-22

국가 코드

30DayMapChallenge: ISO 코드가 국가명에 포함된지 여부를 시각화한 예제 이 프로젝트는 Physicists of many nations – CC BY-NC-ND by Ann Fisher Day 3 of 30DayMapChallenge: « Polygons » (previously)에 영감을 받아 작성되었습니다. Mastodon에서 @opencage@en.osm.town 사용자가 제안한 도전 과제로, 국가의 ISO 3166‑1 alpha‑2 코드가 국가명에 하위 문자열로 포함되어 있는지 여부를 조사하고, 이를 choropleth 맵으로 시각화합니다. 필요한 패키지 로딩 library(dplyr) library(stringr) library(purrr) library(emoji) library(rvest) library(glue) library(gt) library(ggplot2) library(giscoR) library(janitor) library(sf) library(jsonlite) 데이터 준비 # ISO_3166-1_alpha-2 codes iso_3166_a2 <- html_table(na.strings = "") |> pluck(4) |> rename(code = Code, name = `Country name (using title case)`) # giscoR 데이터 사용 (rnaturalearth 보다 알파‑2 코드에 적합) countries <- giscoR::gisco_get_countries() |> clean_names() |> mutate(cntr_id = case_match(cntr_id, "EL" ~ "GR", "GB" ~ "UK", .default = cntr_id)) # Equal Earth 투영 (EPSG:8859) 중심을 태평양에 맞추기 epsg <- 8859 origin <- giscoR::gisco_get_country_codes() |> filter(name == "Longitude of natural origin") |> pull(value) # 바다 배경용 geometry 처리 ocean <- st_as_sfc() |> st_break_antimeridian(lon_0 = origin) |> st_segmentize(units::set_units(100, km)) 문제 해결 – 데이터 정제 후 분석 # ISO 코드가 국가명에 포함된지 여부 results <- iso_3166_a2 |> filter(str_detect(name, regex(code, ignore_case = TRUE))) # 결과 테이블 results_table <- results |> mutate(name_flag = name |> str_split_i(",", 1) |> str_replace_all(c("Lao People's Democratic Republic" = "Laos", "Russian Federation" = "Russia", "Syrian Arab Republic" = "Syria", "Virgin Islands (U.S.)" = "U.S. Virgin Islands"))) |> mutate(flag = map(name_flag, possibly(x, flag(x), otherwise = "")), display = glue("{flag} {name} ({code})")) |> arrange(display) |> select(display) |> gt() |> cols_label(display = "Country") |> cols_align(align = "left") 표 1: ISO 3166‑1 alpha‑2 코드가 국가명에 포함된 국가들 (총 59개) Country 🇦🇫 Afghanistan (AF) Country 🇦🇱 Albania (AL) Country 🇦🇷 Argentina (AR) Country 🇦🇺 Australia (AU) Country 🇦🇿 Azerbaijan (AZ) Country 🇧🇪 Belgium (BE) Country 🇧🇴 Bolivia, Plurinational State of (BO) Country 🇧🇷 Brazil (BR) Country 🇨🇦 Canada (CA) Country 🇨🇴 Colombia (CO) Country 🇨🇺 Cuba (CU) Country 🇨🇾 Cyprus (CY) Country 🇨🇿 Czechia (CZ) Country 🇩🇯 Djibouti (DJ) Country 🇩🇴 Dominican Republic (DO) Country 🇪🇨 Ecuador (EC) Country 🇪🇬 Egypt (EG) Country 🇪� Eritrea (ER) Country 🇪� Ethiopia (ET) Country 🇫🇮 Finland (FI) Country 🇫🇷 France (FR) Country 🇬🇦 Gabon (GA) Country 🇬🇪 Georgia (GE) Country 🇬🇭 Ghana (GH) Country 🇬🇮 Gibraltar (GI) Country 🇬🇷 Greece (GR) Country 🇬🇺 Guam (GU) Country 🇭🇺 Hungary (HU) Country 🇮🇳 India (IN) Country 🇮🇷 Iran, Islamic Republic of (IR) Country 🇮🇹 Italy (IT) Country 🇯🇪 Jersey (JE) Country 🇯🇴 Jordan (JO) Country 🇰🇪 Kenya (KE) Country 🇰🇮 Kiribati (KI) Country 🇱🇦 Lao People's Democratic Republic (LA) Country 🇱🇮 Liechtenstein (LI) Country 🇱🇺 Luxembourg (LU) Country 🇳🇦 Namibia (NA) Country 🇳🇮 Nicaragua (NI) Country 🇳🇴 Norway (NO) Country 🇴🇲 Oman (OM) Country 🇵🇦 Panama (PA) Country 🇵🇪 Peru (PE) Country 🇵🇭 Philippines (PH) Country 🇶🇦 Qatar (QA) Country 🇷🇴 Romania (RO) Country 🇷🇺 Russian Federation (RU) Country 🇷🇼 Rwanda (RW) Country 🇸🇦 Saudi Arabia (SA) Country 🇸🇴 Somalia (SO) Country 🇸🇾 Syrian Arab Republic (SY) Country 🇹🇭 Thailand (TH) Country 🇹🇴 Tonga (TO) Country 🇺🇬 Uganda (UG) Country 🇺🇿 Uzbekistan (UZ) Country 🇻🇪 Venezuela, Bolivarian Republic of (VE) Country 🇻🇮 Virgin Islands (U.S.) (VI) Country 🇾🇪 Yemen (YE) 지도: ISO 코드가 국가명에 포함된지 여부를 chorople
원문 URL
전체 글은 원문 페이지에서 이어서 읽을 수 있습니다.
원문에서 전체 글 읽기
작성자
R-Blogger
출처
R-Blogger
플랫폼
R-Blogger
분류
블로그·해설
언어
한국어
발행일
2025-11-22