服务热线
178 0020 3020
#设置主题
mytheme <- theme_classic() +
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.line = element_blank(),
axis.text = element_blank(),
axis.title = element_blank(),
legend.position = "none")
library(maptools)
library(rgdal)
china_map<-readShapePoly("bou2_4p.shp")
x<-china_map@data
xs<-data.frame(x,id=seq(0:924)-1)
library(ggplot2)
china_map1<-fortify(china_map) #转化为数据框
library(plyr)
china_mapdata<-join(china_map1, xs, type = "full") #合并两个数据框
#区域地图
hebei<-subset(china_mapdata,NAME=="河北省")
ggplot(hebei, aes(x = long, y = lat, group = group,fill=NAME))+
geom_polygon(fill="purple")+
coord_map("polyconic") +
ggtitle("R2-12-河北省-承德")+
geom_path(colour="grey")+
geom_point(x=117.71,y=40.57,size=2,color="gold")+
annotate("text",x=118.5,y=40.57,color="gold",label="承德市")+
mytheme
#pop
pop<-read.table("R2-9-1.csv",header = T,sep = ",")
china_pop<-join(china_mapdata, pop, type = "full")# all rows in x with matching columns in y, then the rows of y that don't match x.
ggplot(china_pop, aes(x = long, y = lat, group = group, fill=pop))+
geom_polygon(colour="green")+
scale_fill_gradient(low="white",high="red") +
coord_map("polyconic") +
ggtitle("R2-12")+
mytheme
附件