[ ⅰ. 미국 주별 범죄율 단계 구분도 ]
-
패키지 준비 → 데이터 준비
-
미국 주(state) 지도 데이터 준비
-
단계 구분도 작성
-
인터랙티브 단계 구분도
ggChropleth() | data | aes(fill= ) | aes(map_id= ) | map | interactive |
표현할 데이터 | 색으로 표현할 변수 |
지역 기준 변수 | 지도 데이터 | 마우스 움직임에 반응하는 구분도 |
더보기
### Step 1:
install.packages("mapproj")
install.packages("ggiraphExtra")
library(ggiraphExtra)
library(tibble)
str(USArrests)
head(USArrests)
# 변수로 처리되지 않은 지역명 → state로 변수화
crime <- rownames_to_column(USArrests, var="state")
crime$state <- tolower(crime$state)
head(crime)
### Step 2:
install.packages("maps")
library(ggplot2)
states_map <- map_data("state")
str(states_map)
### Step 3:
ggChoropleth(data = crime, aes(fill=Murder, map_id=state), map = states_map)
### Step 3:
ggChoropleth(data = crime, aes(fill=Murder, map_id=state), map = states_map, interactive = T)
[ ⅱ. 대한민국 시도별 인구/ 결핵환자 단계 구분도 ]
- 패키지 준비 → 데이터(인구/ 지도) 준비
- 단계 구분도 → 시각화
더보기
### Step 1:
install.packages("stringi") # for using kormaps2014 data
install.packages("devtools") # for using github download fn
devtools::install_github("cardiomoon/kormaps2014")
library(kormaps2014)
library(dplyr)
str(changeCode(korpop1))
str(changeCode(kormap1))
korpop1 <- rename(korpop1, pop='총인구_명', name='행정구역별_읍면동')
options(encoding = "UTF-8")
options(encoding = "CP949")
korpop1$name <- iconv(korpop1$name, "UTF-8", "CP949")
### Step 2:
library(ggplot2)
library(ggiraphExtra)
ggChoropleth(data = korpop1, aes(fill=pop, map_id=code, tooltip = name), map=kormap1, interactive = T)
'데이터 분석 > R' 카테고리의 다른 글
Part Ⅹ: 텍스트 마이닝 (0) | 2021.01.11 |
---|---|
Part Ⅸ: 한국 복지 패널 데이터 분석 (0) | 2021.01.07 |
Part Ⅷ: 데이터 시각화 (0) | 2021.01.07 |
Part Ⅶ: 데이터 정제(결측치 / 이상치) (0) | 2021.01.07 |
Part Ⅵ: 데이터 전처리 (0) | 2021.01.06 |
Part Ⅴ: 데이터 분석 기초 (0) | 2021.01.05 |