국민연금 포트폴리오와 R 시각화로 2024년 기금 현황 들여다보기(feat.누적막대그래프)
요즘 국민연금 기금 고갈에 대한 우려, 자주 들어보셨죠? 뉴스에서는 기금이 2055년쯤 고갈될 가능성이 있다며 걱정을 부추기고, 누군가는 정부의 연기금 관여를 문제 삼기도 해요. 이 모든 정보, 과연 얼마나 믿을 수 있을까요?
그래서 오늘은 “국민연금 포트폴리오” 데이터를 직접 분석해보는 시간을 가져보려고 합니다.
그리고 특별히 R 프로그래밍 언어를 활용해 누적막대그래프 시각화를 만들어 볼 거예요. 눈으로 확인하는 데이터는 달라요. 데이터를 시각화하면서 국민연금의 자산 구조와 연도별 변화를 한눈에 알아봅시다.
국민연금 포트폴리오란?
국민연금 포트폴리오는 쉽게 말해 국민연금이 어떻게 돈을 굴리는지 보여주는 자산의 구성표예요. 국내외 주식, 채권, 대체투자, 부동산 등 다양한 자산에 투자하는데요. 최근에는 위험자산 비중을 높이고 투자 다각화를 강화하고 있어요. 하지만 수익률 향상과 기금 고갈 시점 지연은 여전히 주요 과제로 남아 있습니다.
R로 누적막대그래프: 국민연금 자산 구성 보기
이제 국민연금 포트폴리오 데이터를 시각화해볼까요? 우선 누적막대그래프를 통해 자산 구성 비율을 살펴볼 거예요.
R코드 및 설명
# Install and load necessary packages
if (!requireNamespace("ggplot2", quietly = TRUE)) install.packages("ggplot2")
if (!requireNamespace("reshape2", quietly = TRUE)) install.packages("reshape2")
library(ggplot2)
library(reshape2)
# Create data
portfolio_data <- data.frame(
Year = c("2020", "2021", "2022", "2023", "2024"),
Domestic_Stock = c(148, 160, 170, 185, 200),
Foreign_Stock = c(351, 370, 390, 410, 430),
Bond = c(320, 310, 300, 290, 280),
Alternative = c(171, 180, 190, 200, 210)
)
# Transform data
melted_data <- melt(portfolio_data, id.vars = "Year")
names(melted_data)[names(melted_data) == "variable"] <- "Asset_Type"
# Calculate totals separately
totals <- aggregate(value ~ Year, melted_data, sum)
names(totals) <- c("Year", "Total")
# Calculate percentages
melted_data$percentage <- ave(melted_data$value,
melted_data$Year,
FUN = function(x) x / sum(x) * 100)
# Create plot
ggplot(melted_data, aes(x = Year, y = value)) +
geom_bar(aes(fill = Asset_Type), stat = "identity") +
geom_text(aes(label = sprintf("%d\n(%.1f%%)", value, percentage)),
position = position_stack(vjust = 0.5),
color = "white",
size = 3) +
geom_text(data = totals,
aes(y = Total, label = Total),
position = position_stack(vjust = 1.05),
color = "black",
fontface = "bold") +
labs(title = "National Pension Fund Asset Composition",
x = "Year",
y = "Asset Value (Trillion KRW)",
fill = "Asset Type") +
theme_minimal()
R 코드 상세 해설
1. 패키지 설치 및 로드
if (!requireNamespace("ggplot2", quietly = TRUE)) install.packages("ggplot2") if (!requireNamespace("reshape2", quietly = TRUE)) install.packages("reshape2") library(ggplot2) library(reshape2)
requireNamespace()를 사용하여 필요한 패키지가 설치되어 있는지 확인- 패키지가 없다면 자동으로 설치
ggplot2: 데이터 시각화를 위한 패키지reshape2: 데이터 구조 변환을 위한 패키지2. 데이터 생성
portfolio_data <- data.frame( Year = c("2020", "2021", "2022", "2023", "2024"), Domestic_Stock = c(148, 160, 170, 185, 200), Foreign_Stock = c(351, 370, 390, 410, 430), Bond = c(320, 310, 300, 290, 280), Alternative = c(171, 180, 190, 200, 210) )
data.frame생성- 연도별 각 자산 유형의 금액 데이터 포함
- 열 구조: 연도(Year)와 4개의 자산 유형
3. 데이터 변환
melted_data <- melt(portfolio_data, id.vars = "Year") names(melted_data)[names(melted_data) == "variable"] <- "Asset_Type"
melt()함수를 사용하여 wide format에서 long format으로 변환id.vars = "Year"로 Year 열을 식별자로 지정- 변수명을 ‘variable’에서 ‘Asset_Type’으로 변경하여 의미를 명확히 함
4. 총액 계산
totals <- aggregate(value ~ Year, melted_data, sum) names(totals) <- c("Year", "Total")
aggregate()함수를 사용하여 연도별 총액 계산- 결과 데이터프레임의 열 이름을 Year와 Total로 지정
5. 비율 계산
melted_data$percentage <- ave(melted_data$value, melted_data$Year, FUN = function(x) x / sum(x) * 100)
ave()함수를 사용하여 각 연도별로 자산 비율 계산- 각 값을 해당 연도의 총합으로 나누고 100을 곱하여 퍼센트 계산
6. 그래프 생성
ggplot(melted_data, aes(x = Year, y = value)) + geom_bar(aes(fill = Asset_Type), stat = "identity") + geom_text(aes(label = sprintf("%d\n(%.1f%%)", value, percentage)), position = position_stack(vjust = 0.5), color = "white", size = 3) + geom_text(data = totals, aes(y = Total, label = Total), position = position_stack(vjust = 1.05), color = "black", fontface = "bold") + labs(title = "National Pension Fund Asset Composition", x = "Year", y = "Asset Value (Trillion KRW)", fill = "Asset Type") + theme_minimal()
ggplot(): 기본 그래프 객체 생성geom_bar(): 막대 그래프 생성stat = "identity": 실제 값을 그대로 사용fill = Asset_Type: 자산 유형별로 색상 구분- 첫 번째
geom_text(): 각 막대 구간에 값과 비율 표시sprintf(): 텍스트 포맷 지정position_stack(): 텍스트 위치 조정- 두 번째
geom_text(): 연도별 총액 표시vjust = 1.05: 텍스트를 막대 위에 배치fontface = "bold": 굵은 글씨체 적용labs(): 그래프 제목과 축 레이블 설정theme_minimal(): 깔끔한 테마 적용
국민연금의 독립성과 개혁, 왜 중요한가?
국민연금 기금 고갈 우려 속에서 “국민연금의 독립성과 개혁”은 매우 중요한 화두가 되고 있어요.
국민연금이 정치적 간섭에서 자유롭고 안정적으로 운용되기 위해서는 몇 가지 변화가 필요합니다.

필요한 변화
- 운용 독립성 강화: 기금운용본부를 정부 영향력에서 분리하고, 전문가 중심의 의사결정 구조를 만들어야 합니다.
- 투명성 확대: 기금 운용 상태를 국민들이 쉽게 이해할 수 있도록 정기적으로 보고하고 공개해야 해요.
- 투자 다각화: 위험 관리와 수익률 향상을 위해 글로벌 투자와 안정적 자산 배분을 강화해야 합니다.
국민연금 포트폴리오, 데이터로 바라보기
오늘은 국민연금 포트폴리오를 R 시각화를 통해 분석해봤습니다. 누적막대그래프를 통해 국민연금의 자산 구성과 연도별 자산 증가 추이를 살펴보니, 데이터는 우리에게 객관적 시각을 제공합니다.
그리고 국민연금의 독립성과 개혁이 왜 중요한지도 짚어봤어요. 이제 여러분의 목소리를 더해 주세요! 여러분의 참여가 우리의 미래를 바꿀 수 있습니다!






