服务热线
178 0020 3020
任务1
直接用下载的数据
install.packages("maptools") install.packages("plyr") install.packages("rgdal") library(maptools) library(rgdal) library(ggplot2) library(plyr) mytheme<-theme(panel.background=element_blank(),panel.grid=element_blank(),axis.text=element_blank(),axis.ticks=element_blank(),axis.title=element_blank(),legend.position = "none") china_map<-rgdal::readOGR(file.choose()) map<-china_map@data maps<-data.frame(x,id=seq(0:924)-1) china_map1<-fortify(china_map) china_mapdata<-join(china_map1, maps, type = "full") BJ<-subset(china_mapdata,NAME=="北京市") ggplot(BJ,aes(x=long,y=lat,group=group,fill=NAME))+geom_polygon(fill="green" )+geom_path(colour = "grey40")+ggtitle("R2-01-北京-西城")+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
任务2
install.packages("mapproj") library(mapproj) 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(0.9,0.4)) population<-read.csv(file.choose()) mydata<-as.data.frame(population) mydata pop<-join(china_mapdata, mydata, type = "full") ggplot(pop,aes(x=long,y=lat,group=group,fill=pop))+geom_polygon()+coord_map("polyconic")+geom_polygon(colour="green")+scale_fill_gradient(low="white",high="red") +ggtitle("R2-01")+mytheme
附件