IRONAnthony 跟着你的,我也绘制了湖南地图
安装并加载必要的包
install.packages("mapchina") # 如果尚未安装
install.packages("tidyverse") # 如果尚未安装
install.packages("sf") # 如果尚未安装
library(mapchina)
library(tidyverse)
library(sf)
假设 'china' 是一个包含中国各省、市、县的sf对象
过滤出湖南省的数据
province <- china %>%
filter(Name_Province == "湖南省") # 仅选择湖南省
计算城市和县的几何体
cities <- province %>%
group_by(Name_Perfecture) %>%
summarise(geometry = st_union(geometry))
countries <- province %>%
group_by(Name_County) %>%
summarise(geometry = st_union(geometry))
绘制湖南省的地图
ggplot() +
geom_sf(data = countries,
aes(fill = factor(generate_map_colors(countries))),
linetype = "solid", size = 0.5) +
scale_fill_brewer(palette = "Pastel1") +
geom_sf(data = province, alpha = 0, linetype = "dashed", size = 0.2) +
geom_sf(data = cities, alpha = 0, linetype = "solid", size = 1.2) +
geom_sf_label(data = countries, aes(label = Name_County), size = 2.3) +
theme_bw() +
theme(legend.position = "none")