服务热线
178 0020 3020
任务1
library(maptools)
library(ggplot2)
library(plyr)
mymap <-readShapePoly("/Users/Hong/Desktop/data/data10/bou2_4p.shp")
mymapd <- fortify(mymap)
temp<-mymap@data
xs<-data.frame(temp,id=seq(0:924)-1)
china_mapdata<-join(mymapd, xs, type = "full")
guangxi <- subset(china_mapdata,NAME=="广西壮族自治区")
mytheme<-theme(plot.title=element_text(),axis.title=element_blank(),axis.text=element_blank(),axis.line=element_blank(),panel.grid.major=element_blank(),panel.border=element_blank(),panel.background=element_rect(fill="white"),panel.grid.minor.y=element_blank(),panel.grid.minor.x=element_blank(),legend.position="none")
p<-ggplot(guangxi,aes(x=long,y=lat,group=group,fill=NAME))+geom_polygon(fill="yellow")+geom_path(colour="grey40")+ggtitle("R2-37-广西-桂林")+geom_text(mapping=aes(x=108.3,y=23.5,label=NAME),color="red",cex=5)+geom_point(aes(x=108.3,y=22.8),colour="green",size=3)+geom_point(aes(x=110.28,y=25.29),colour="green",size=1.5)+annotate("text",x=108.3,y=21.8,label="南宁")+annotate("text",x=110.28,y=24.2,label="桂林")+coord_map("polyconic")
p+mytheme
任务2
library(maptools)
library(ggplot2)
library(plyr)
mymap <-readShapePoly("/Users/Hong/Desktop/data/data10/bou2_4p.shp")
mymapd <- fortify(mymap)
temp<-mymap@data
xs<-data.frame(temp,id=seq(0:924)-1)
china_mapdata<-join(mymapd, xs, type = "full")
mytheme<-theme(plot.title=element_text(),axis.title=element_blank(),axis.text=element_blank(),axis.line=element_blank(),panel.grid.major=element_blank(),panel.border=element_blank(),panel.background=element_rect(fill="white"),panel.grid.minor.y=element_blank(),panel.grid.minor.x=element_blank())
popdata <-read.csv("/Users/Hong/Desktop/data/data10/R2-9-1.csv")
mydata<- as.data.frame(popdata)
pop <- join(china_mapdata,mydata,type="full")
ggplot(pop,aes(x=long,y=lat,group=group,fill=pop))+geom_polygon()+coord_map()+scale_fill_gradient(low="white",high="red")+geom_path(colour="green")+ggtitle("R2-37")+mytheme
附件