기후 데이터 시각화 (R ggplot2) (초급)
초급
정량 분석
environmental
r
난이도: 초급 — 입문자를 위한 간략화된 설명입니다.
개요
기후 변화 데이터를 R의 ggplot2로 시각화한다. 연평균 기온 추세와 지역별 비교를 통해 기후 변화의 시공간 패턴을 파악한다.
분석 절차
1단계: 시계열 추세 시각화
geom_line으로 연도별 기온 추세를 그리고, geom_smooth(method = “loess”)로 추세선을 추가한다.
2단계: 지역별 비교
facet_wrap으로 지역별 패널을 생성하여 지역 간 기온 변화 패턴을 비교한다.
3단계: 색상 팔레트
scale_color_brewer로 ColorBrewer 팔레트를 적용하여 가독성을 높인다.
결과 해석
기온이 우상향 추세를 보이면 기후 온난화의 증거다. 지역별 추세 기울기가 다르면 지역 간 기후 변화 속도에 차이가 있음을 의미한다.
코드 예제
library(ggplot2)
library(dplyr)
library(tidyr)
# 데이터 로드
climate <- read.csv('climate_data.csv')
# 연도별 기온 추세
ggplot(climate, aes(x = year, y = avg_temp)) +
geom_line(color = "#E74C3C", size = 1) +
geom_smooth(method = "loess", se = TRUE, fill = "grey80") +
labs(title = "연평균 기온 변화",
x = "연도", y = "평균 기온 (°C)") +
theme_minimal()
# 지역별 비교
ggplot(climate, aes(x = year, y = avg_temp, color = region)) +
geom_line(size = 0.8) +
facet_wrap(~ region, scales = "free_y") +
scale_color_brewer(palette = "Set1") +
labs(title = "지역별 기온 변화") +
theme_minimal()
참고문헌
Wickham, H. (2016). ggplot2: Elegant Graphics for Data Analysis (2nd ed.). Springer.
학습 팁
이 방법론은 초급 수준입니다. 먼저 기초 통계 개념을 익힌 후 진행하세요. SPSS나 R의 기본 조작법을 숙지하면 더 수월합니다.
코드 예제
R
library(ggplot2) library(dplyr) library(tidyr) # 데이터 로드 climate <- read.csv('climate_data.csv') # 연도별 기온 추세 ggplot(climate, aes(x = year, y = avg_temp)) + geom_line(color = "#E74C3C", size = 1) + geom_smooth(method = "loess", se = TRUE, fill = "grey80") + labs(title = "연평균 기온 변화", x = "연도", y = "평균 기온 (°C)") + theme_minimal() # 지역별 비교 ggplot(climate, aes(x = year, y = avg_temp, color = region)) + geom_line(size = 0.8) + facet_wrap(~ region, scales = "free_y") + scale_color_brewer(palette = "Set1") + labs(title = "지역별 기온 변화") + theme_minimal()
참고문헌
Wickham, H. (2016). ggplot2: Elegant Graphics for Data Analysis (2nd ed.). Springer.