服务热线
178 0020 3020
任务一:
library("ggplot2")
library("plyr")
library("maptools")
library(“rgdal”)
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=readShapePoly("bou2_4p.shp")
x=china_map@data
xs=data.frame(x,id=seq(0:924)-1)
china_map1=fortify(china_map)
china_mapdata=join(china_map1, xs, type = "full")
xinjiang=subset(china_mapdata,NAME=="新疆维吾尔自治区")
a=ggplot(xinjiang,aes(x=long,y=lat,group=group,fill=NAME))+geom_polygon(fill="pink")+geom_path(colour="grey40")+ggtitle("R2-22-新疆-哈密")
p=a+geom_text(mapping=aes(x=75,y=49,label=NAME),color="black",cex=3)
p
w=p+geom_point(aes(x=87.36,y=43.45),colour="blue",size=3,pch=19)+annotate("text",x=87.2,y=43,label="乌鲁木齐")
w
h=w+geom_point(aes(x=93.28,y=42.50),colour="blue",size=1.5)+annotate("text",x=93.1,y=41.9,label="哈密")
h
install.packages("mapproj")
library("mapproj")
e=h+coord_map("polyconic")+mytheme
e
任务二:
> library(ggplot2)
> library(maptools)
> 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 = c(1.0,0.5))
> 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_mapdata<-join(china_map1, xs, type = "full")
> data<-read.csv(file.choose())
> mydata<-as.data.frame(data)
> pop<-join(china_mapdata,mydata,type="full")
>m<-ggplot(pop,aes(x=long,y=lat,group=group,fill=pop))+geom_polygon()+coord_map("polyconic")
>n<-m+scale_fill_gradient(low="white",high="red")+geom_path(colour="green")+ggtitle("R2-22")+mytheme
>n
附件