library(tidyverse) library(sf) library(ggspatial) library(ggnewscale)
mycrs <- "+proj=aea +lat_0=0 +lon_0=105 +lat_1=25 +lat_2=47 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs"
st_bbox(c(xmin = -2925762.0, xmax = 2507277.8, ymax = 6221888.6, ymin = 377031.1), crs = st_crs(mycrs)) %>% st_as_sfc() -> longbbox
read_sf("chinaprov2021long/chinaprov2021long.shp") %>% filter(!is.na(省代码)) -> provmap
read_sf("chinaprov2021long/chinaprov2021long_line.shp") %>% filter(class %in% c("九段线", "海岸线")) %>% select(class) -> provlinemap
read_sf("china_neighboring_long/china_neighboring_long.shp") -> china_neighboring_long
readxl::read_xlsx("瞪羚、独角兽、创新型企业经纬度数据.xlsx") %>% filter(!is.na(经度)) -> pointdf
pointdf %>% st_as_sf(coords = c("经度", "纬度"), crs = 4326) %>% st_transform(mycrs) -> pointdfsf
pointdfsf
pointdfsf %>% st_drop_geometry() %>% count(省, 省代码) -> provdf
provmap %>% left_join(provdf) %>% mutate(n = if_else(is.na(n), 0, n)) -> provdf2
provdf2$n %>% quantile(probs = 1:8/8, digits = 1) %>% as.integer() %>% unique() -> cutlist
cutlist
provdf2 %>% mutate(group = cut(n, breaks = c(0, unique(cutlist)), include.lowest = T, labels = c("<= 8", "8~28", "28~58", "58~159", "159~513", "513~870", "870~2459", "> 2450"))) -> provdf3
provdf3 %>% ggplot() + geom_sf(data = longbbox, fill = "#BBD1EB") + geom_sf(aes(fill = group), color = "gray", linewidth = 0.01) + geom_sf(data = china_neighboring_long, fill = "#EDEDED") + stat_sf_coordinates(data = china_neighboring_long, geom = "text", color = "gray", aes(label = country_cn), family = cnfont, size = 3) + geom_sf(data = provlinemap, aes(color = class, linewidth = class), show.legend = F) + scale_color_manual( values = c("九段线" = "#A29AC4", "海岸线" = "#0055AA") ) + scale_linewidth_manual( values = c("九段线" = 0.6, "海岸线" = 0.3) ) + scico::scale_fill_scico_d(palette = "acton", name = "公司数量", end = 0.95) + new_scale_color() + geom_sf(data = pointdfsf, aes(color = 省), size = 0.1, show.legend = F) + scale_color_manual(values = paletteer::paletteer_d("ggsci::default_igv", n = 32)) + annotation_scale(location = "bl", width_hint = 0.3, text_family = cnfont) + labs(title = "瞪羚、独角兽、创新型企业地理分布", subtitle = "数据爬取&绘制:微信公众号 RStata", caption = "数据来源:瞪羚云网站") + theme(axis.title.x = element_blank(), axis.title.y = element_blank()) + annotation_north_arrow( location = "tr", which_north = "false", pad_y = unit(0.1, "cm"), style = north_arrow_fancy_orienteering( text_family = cnfont ) ) + theme(legend.position = c(0.2, 0.25)) -> p4
ggsave("pic4.png", width = 8, height = 9, device = png)
|
评论