# 加载必要包
library(tidyverse)
library(scales)
library(ggrepel)
# 设置中文字体支持 (Windows系统)
if(.Platform$OS.type == "windows"){
windowsFonts(SimHei = windowsFont("SimHei"))
theme_set(theme_minimal(base_family = "SimHei"))
}
# 创建数据框
gdp_data <- data.frame(
年份 = 2015:2024,
国民总收入 = c(699224.5, 757492.0, 846292.7, 931972.5, 1003108.4, 1026751.9, 1165816.8, 1223706.8, 1284773.9, 1339814.6),
国内生产总值 = c(702511.5, 761193.0, 847382.9, 936010.1, 1005872.4, 1034867.6, 1173823.0, 1234029.4, 1294271.7, 1349083.5),
第一产业 = c(57774.6, 60139.2, 62099.5, 64745.2, 70473.6, 78030.9, 83216.5, 88207.0, 89169.1, 91413.9),
第二产业 = c(281338.9, 295427.8, 331580.5, 364835.2, 379860.0, 381985.8, 447138.2, 467629.6, 475936.1, 492087.1),
第三产业 = c(363397.9, 405626.0, 453702.9, 506429.8, 555538.9, 574850.9, 643468.4, 678192.7, 729166.5, 765582.5)
)
# 转换为长格式
gdp_long <- gdp_data %>%
pivot_longer(
cols = c(第一产业, 第二产业, 第三产业),
names_to = "产业类型",
values_to = "产值"
) %>%
mutate(产业类型 = factor(产业类型,
levels = c("第一产业", "第二产业", "第三产业"),
labels = c("农业", "工业", "服务业")))
# 创建GDP增长标签数据
growth_labels <- gdp_data %>%
mutate(
gdp_growth = round((国内生产总值 - lag(国内生产总值)) / lag(国内生产总值) * 100, 1),
label = ifelse(!is.na(gdp_growth),
paste0(round(国内生产总值/10000, 1), "万亿\n(+", gdp_growth, "%)"),
paste0(round(国内生产总值/10000, 1), "万亿"))
)