服务热线
178 0020 3020
作业1
> library(maptools)
> library(ggplot2)
> library(plyr)
> 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")
> setwd("C:\\Users\\LM\\Desktop\\地图")
> 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")
> guangdong<-subset(china_mapdata,NAME=="广东省")
>ggplot(guangdong,aes(x=long,y=lat,group=group,fill=NAME))+geom_polygon(fill="yellow" )+geom_path(colour = "grey40")+ggtitle("R2-28-广东-清远")
>p<-ggplot(guangdong,aes(x=long,y=lat,group=group,fill=NAME))+geom_polygon(fill="yellow" )+geom_path(colour = "grey40")+ggtitle("R2-28-广东-清远")
> p+geom_text(mapping = aes(x=113.37,y=24.50,label=NAME),color="red",cex=6)
> h<- p+geom_text(mapping = aes(x=113.37,y=24.50,label=NAME),color="red",cex=6)
> h+geom_point(aes(x=113.14,y=23.08),colour="red",size=4,pch=19)
> w<-h+geom_point(aes(x=113.14,y=23.08),colour="red",size=4,pch=19)
> w+geom_point(aes(x=113.01,y=23.42),colour="red",size=2)
> a<-w+geom_point(aes(x=113.01,y=23.42),colour="red",size=2)
> a+annotate("text",x=113.34,y=22.88,label="广州")
> q<-a+annotate("text",x=113.34,y=22.88,label="广州")
> q+annotate("text",x=113.22,y=23.62,label="清远")
>z<-q+annotate("text",x=113.22,y=23.62,label="清远")
> install.packages("mapproj")
> library(mapproj)
> z+coord_map("polyconic")+mytheme
作业2
>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))
> data<-read.csv(file.choose())
> mydata<-as.data.frame(data)
> pop<-join(china_mapdata, mydata, type = "full")
>ggplot(pop,aes(x=long,y=lat,group=group,fill=pop))+geom_polygon()+coord_map("polyconic")+scale_fill_gradient(low="white",high="red")+geom_path(colour = "yellow")+ggtitle("R2-28")+mytheme
>p<-ggplot(pop,aes(x=long,y=lat,group=group,fill=pop))+geom_polygon()+coord_map("polyconic")+scale_fill_gradient(low="white",high="red")+geom_path(colour = "yellow")+ggtitle("R2-28")+mytheme
附件