R2-37-第九期-地图

洪学志 2018-01-02 22:04:45 阅读: 1088

任务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

10-1.png

任务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

10-2.png



 

 
邀请讨论

附件

{{f.title}} 大小 {{f.file_size}} 下载 {{f.count_download}} 金币 {{f.count_gold}}
{{item.nick_name}} 受邀请回答 {{item.create_time}}
{{item.refer_comment.nick_name}} {{item.refer_comment.create_time}}

附件

{{f.title}} 大小 {{f.file_size}} 下载 {{f.count_download}} 金币 {{f.count_gold}}
切换到完整回复 发送回复
赞({{item.count_zan}}) 踩({{item.count_cai}}) 删除 回复 关闭
科研狗©2015-2024 科研好助手,京ICP备20005780号-1 建议意见

服务热线

178 0020 3020

微信服务号