1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
| haven::read_dta('data/各省历年GDP.dta') |> dplyr::filter(省份 != "中国", 年份 %in% 2014:2019) |> full_join(prov) |> st_sf() |> select(省份, 年份, 地区生产总值_亿元) -> provdf
bind_rows( provdf |> dplyr::filter(年份 == 2014 | is.na(年份)) |> mutate(年份 = if_else(is.na(年份), 2014, 年份)), provdf |> dplyr::filter(年份 == 2015 | is.na(年份)) |> mutate(年份 = if_else(is.na(年份), 2015, 年份)), provdf |> dplyr::filter(年份 == 2016 | is.na(年份)) |> mutate(年份 = if_else(is.na(年份), 2016, 年份)), provdf |> dplyr::filter(年份 == 2017 | is.na(年份)) |> mutate(年份 = if_else(is.na(年份), 2017, 年份)), provdf |> dplyr::filter(年份 == 2018 | is.na(年份)) |> mutate(年份 = if_else(is.na(年份), 2018, 年份)), provdf |> dplyr::filter(年份 == 2019 | is.na(年份)) |> mutate(年份 = if_else(is.na(年份), 2019, 年份)) ) -> provdf2
provdf2 |> mutate(gdp = case_when( is.na(地区生产总值_亿元) ~ "无数据", between(地区生产总值_亿元, 0, 20000) ~ "< 20 千亿", between(地区生产总值_亿元, 20000, 40000) ~ "20~40千亿", between(地区生产总值_亿元, 40000, 60000) ~ "40~60千亿", between(地区生产总值_亿元, 60000, 80000) ~ "60~80千亿", between(地区生产总值_亿元, 80000, 200000) ~ "> 80千亿", )) |> mutate(gdp = factor(gdp, levels = c("无数据", "< 20 千亿", "20~40千亿", "40~60千亿", "60~80千亿", "> 80千亿"))) -> provdf3
ggplot(provdf3) + geom_sf(aes(fill = gdp), color = "gray30", size = 0.2) + facet_wrap(~年份, nrow = 2) + labs(title = "2014~2019 年中国各省地区生产总值", caption = "数据来源:CSMAR 国泰安数据库") + scico::scale_fill_scico_d(palette = "davos", name = NULL, direction = -1) + scale_x_continuous(expand = c(0.001, 0.001)) + scale_y_continuous(expand = c(0.001, 0.001)) + annotation_scale( width_hint = 0.2, height = unit(0.15, "cm"), text_family = cnfont ) + annotation_north_arrow( location = "bl", which_north = "false", pad_y = unit(0.4, "cm"), pad_x = unit(0.8, "cm"), width = unit(0.6, "cm"), height = unit(0.8, "cm"), style = north_arrow_fancy_orienteering( text_family = cnfont ) ) + theme(axis.title.x = element_blank(), axis.title.y = element_blank(), strip.text = element_text(family = cnfont, colour = "gray30", hjust = 0.5), legend.position = "bottom", plot.margin = unit(rep(0.5, 4), "cm"), axis.text.x = element_blank(), axis.text.y = element_blank(), panel.grid.major = element_blank()) + guides(fill = guide_legend(nrow = 1, title.position = "top", title.hjust = 0.5, label.position = "top"))
|