"R實(shí)戰(zhàn)"專(zhuān)題·第25篇 通常很多國(guó)人發(fā)表文章的時(shí)候會(huì)附帶一張中國(guó)地圖(采樣圖為主),或者是在做meta分析(以我國(guó)為主)也會(huì)附上一張數(shù)據(jù)對(duì)應(yīng)的信息分布圖。然后,目前所發(fā)表的文章中存在大多數(shù)錯(cuò)誤的中國(guó)地圖,容易誤導(dǎo)大家,比如沒(méi)有顯示九段線(xiàn),或者是各類(lèi)群島沒(méi)有顯示。今天,利用R語(yǔ)言與大家分享一份標(biāo)準(zhǔn)中國(guó)地圖(基礎(chǔ)版)。下一期:標(biāo)準(zhǔn)中國(guó)地圖(進(jìn)階版)~# 標(biāo)準(zhǔn)中國(guó)地圖 ----------------- china_geo <- "中國(guó)省級(jí)地圖GS(2019)1719號(hào).geojson" nine_line <- "九段線(xiàn)GS(2019)1719號(hào).geojson" china_m <- sf::read_sf(china_geo) nine_line <- sf::read_sf(nine_line) head(china_m)
load("I:\\R language\\R語(yǔ)言中國(guó)地圖包含九段線(xiàn)\\China-map.RData") china_plot <- map[[1]]
# 隨機(jī)構(gòu)建的數(shù)據(jù) random_sample <- sample(rownames(china_plot) ,3000) rs <- china_plot[c(random_sample),] unique(rs$class)
# 對(duì)樣點(diǎn)數(shù)據(jù)進(jìn)行轉(zhuǎn)換 library(sf) plot <- st_as_sf(rs,coords = c("long", "lat"),crs=4326)
library(ggspatial) library(ggplot2) library(cowplot) China_m <- ggplot() + # 利用轉(zhuǎn)換后的樣點(diǎn)進(jìn)行繪制 geom_sf(data = china_m, fill=NA) + geom_sf(data = nine_line, color='gray50',size=.8)+ geom_sf(data = plot,aes(color=class, size=piece),shape=16, alpha=0.7)+ # coord_sf(ylim = c(-2387082,1654989),crs="+proj=laea +lat_0=40 +lon_0=104")+ scale_color_manual(values = c("#9BBB59", "#957DB1"))+ scale_size(range = c(1,5))+ # 比例尺的繪制 annotation_scale(location = "bl",text_face = "bold", text_family = "Times_New_Roman") + # 向北指南標(biāo)簽的繪制 annotation_north_arrow(location = "tl", which_north = "false", style = north_arrow_fancy_orienteering, )+ guides(fill = guide_legend(override.aes = list(size = 3), title = "", label.position = "right", nrow=4), size = guide_legend(title = "", label.position = "right", nrow=4)) + theme_bw()+ theme( text = element_text(family = "Times_New_Roman",size = 16,face = "bold"), panel.background = element_blank(), panel.grid.major = element_line(colour = "grey90",size=.2), legend.key = element_rect(fill = "white"), legend.position = "right", ) China_m 圖中用到的文件可以加我們的群獲得,如果有什么問(wèn)題想要討論也可以加群交流。 方法如下:
|