R2-35第二期-第九次作业ggplot地图

德先森 2018-01-02 19:32:07 阅读: 1197

install.packages("maptools")
install.packages("plyr")
library(maptools)
library(ggplot2)
library(plyr)T1.png

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")
data<-china_map@data
d<-data.frame(data,id=seq(0:924)-1)
china_map1<-fortify(china_map)
china_mapdata<-join(china_map1, d, type = "full")
BJ<-subset(china_mapdata,NAME=="北京市")
p<-ggplot(BJ,aes(x=long,y=lat,group=group,fill=NAME))+geom_polygon(fill="yellow" )+geom_path(colour = "grey40")+ggtitle("R2-35-北京-海淀")+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
p


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))scale_fill_gradient(low="white",high="red")+geom_path(colour = "yellow")+ggtitle("R2-35")+mytheme
population<-read.csv("R2-9-1.csv")
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-35")+mytheme

T2.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

微信服务号