pop.rar
(812 Bytes)
本附件包括:- pop.csv
分省矢量数据,不在本论坛上传。请同学自己想办法。
- library(ggplot2)
- library(dplyr)
- library(maptools)
- library(sf)
- orig <- st_read("CN-sheng-A.shp", stringsAsFactors = FALSE) #矢量数据读入
- pop<-read.csv("pop.csv",header=T) #人口数据读入
- orig<-orig%>%left_join(pop, by="name") #合并数据
- #绘制分省人口
- ggplot(orig) +
- geom_sf(aes(fill = `人口`,geometry = `geometry`), size = 1, color = "black") +
- geom_sf_text(
- aes(label = `name`, geometry = `geometry`),
- color = "white",
- size = 2,
- check_overlap = FALSE,
- family="GB1"
- )+
- scale_fill_gradient(low = "green", high = "red",aesthetics = "fill")+
- guides(fill = guide_colorbar(title = "人口", title.position = "top",family="GB1"))+
- theme(panel.background = element_rect(fill = "white", colour = "black"),legend.position=c(0,0), legend.justification = c(0, 0), axis.title = element_blank())
- ggsave("chinapop.png",width=15,height=20,unit="cm",dpi=300) #生成300dpi的png,可用,但不如pdf文件好用
结果如图:



雷达卡





京公网安备 11010802022788号







