아래와 같은 이미지를 R package에 있는 데이터를 이용하여 그릴 수 있는데요, 저는 두 국가 - 제가 태어나고 자란 나라와 현재 거주하는 나라를 정해서 그려보았습니다.


색도 여러가지 시도해볼 수 있습니다. 아래 글에 ggplot에서 사용할 수 있는 657가지 색의 이름과 종류를 마지막에 정리해두었으니, 참고하셔서 각각 다른 나라 지도를 그려보는 것으로 시도해보시면 좋을 것 같습니다.
2023.05.26 - [DataViz] - ggplot2 scatterplot 기초
ggplot2 scatterplot 기초
1. DATA CPS85: R의 mosaicData pacakage에 있는 CPS85데이터를 사용합니다. CPS는 The Current Population Survey의 약자로, 인구 조사(census)를 하는 기간 사이에 정보를 보완하는 데 사용됩니다. 이 데이터는 성별,
minitistics.tistory.com
위의 두 국가 지도를 만들기 위한 코드는 다음과 같습니다:
## @minitistics
library(tidyverse)
library(stringr)
library(ggplot2)
## world map
world <- map_data("world")
## Korea
korea <- world %>%
filter(str_like(region, "%Korea%"))
## Korea map
ggplot(korea, aes(long, lat, group = group, color = region, fill = region)) +
geom_polygon() +
scale_color_manual(values = c("peachpuff", "salmon1")) +
scale_fill_manual(values = c("peachpuff", "salmon1")) +
coord_quickmap() +
theme_void() +
labs(camption = "by @minitistics")
## Australia
aus <- world %>%
filter(str_like(region, "%Australia%"))
## Australia map
ggplot(aus, aes(long, lat, group = group, color = region, fill = region)) +
geom_polygon() +
scale_color_manual(values = c("cornflowerblue")) +
scale_fill_manual(values = c("cornflowerblue")) +
coord_quickmap() +
theme_void() +
labs(camption = "by @minitistics")
반응형
'호주 데이터 분석가 > DataViz' 카테고리의 다른 글
[R] 한국 인구밀도 R에서 3D로 그리기 (0) | 2024.08.27 |
---|---|
[R] Korea Forest in 3D (2) | 2024.08.27 |
[R] 호주 인구분포 - Are there any people? (0) | 2024.08.26 |
[R] Carbon Dioxide uptake in Grass Plants(식물의 이산화탄소 흡수량 분석) (0) | 2023.07.06 |
ggplot2 scatterplot 기초 (0) | 2023.05.26 |
댓글