服务热线
178 0020 3020
install.packages("maptools") install.packages("plyr") library(maptools) library(ggplot2) library(rgdal) library(plyr) mytheme_map <- theme(panel.grid = element_blank(), panel.background = element_blank(), axis.text = element_blank(), axis.ticks = element_blank(), axis.title = element_blank()) setwd('D:/R-LMT/9') china_map<-readShapePoly("bou2_4p.shp") x<-china_map@data xs<-data.frame(x,id=seq(0:924)-1) china_map1<-fortify(china_map) china_map_data<-join(china_map1,xs,type='full') BJ<-subset(china_map_data,NAME=="北京市") p<-ggplot(BJ,aes(x=long,y=lat,group=group,fill=NAME))+geom_polygon(fill="yellow" )+geom_path(colour = "grey40")+ggtitle("R2-24-北京-海淀")+geom_text(mapping = aes(x=116.7,y=40.5,label=NAME),color="red",cex=6)+geom_point(aes(x=116.17,y=39.97),colour="red",size=4,pch=19)+annotate("text",x=116.15,y=40,color="red",label="海淀")+ mytheme_map p
install.packages("mapproj") library(mapproj) merge_data<-join(china_map1,xs,type = "full") pop<-read.csv("R2-9-1.csv") merge_xs<-join(merge_data, pop, by = "NAME", type = "full") mytheme<-theme( panel.background = element_blank(), panel.grid = element_blank(), axis.text = element_blank(), axis.ticks = element_blank(), axis.title = element_blank(), legend.position = c(1.0,0.5)) ggplot(merge_xs, aes(x = long, y = lat, group = group,fill=pop) )+ geom_polygon()+ scale_fill_gradient(low = "white",high = "red")+ geom_path(colour = "green")+ ggtitle("R2-24 中国人口信息与行政区域结合图")+mytheme
附件