服务热线
178 0020 3020
library(maptools)
> china_map<-readShapePoly("bou2_4p.shp")
Warning message:
use rgdal::readOGR or sf::st_read
>
> x<-china_map@data
> xs<-data.frame(x,id=seq(0:924)-1)
> library(ggplot2)
> china_map1<-fortify(china_map)
Regions defined for each Polygons
> library(plyr)
> china_mapdata<-join(china_map1, xs, type = "full")
Joining by: id
> data<-read.csv("R2-9.csv")
> pop<-data.frame(NAME,pop)
> china_pop<-join(china_mapdata, pop, type = "full")
Joining by: NAME
> ggplot(china_pop, aes(x = long, y = lat, group = group,fill=pop))+
+ geom_polygon(aes())+
+ scale_fill_gradient(low="white",high="red")+
+ geom_path(colour = "grey40")+
+ ggtitle("R2-07")
> getwd()
[1] "C:/Users/Administrator/Desktop/R语言"
> library(maptools)
> china_map<-readShapePoly("bou2_4p.shp")
Warning message:
use rgdal::readOGR or sf::st_read
> x<-china_map@data
> xs<-data.frame(x,id=seq(0:924)-1)
> library(ggplot2)
> china_map1<-fortify(china_map)
Regions defined for each Polygons
> library(plyr)
> china_mapdata<-join(china_map1, xs, type = "full")
Joining by: id
> Hunan<-subset(china_mapdata,NAME=="湖南省")
>ggplot(Hunan, aes(x = long, y = lat, group = group,fill=NAME))+
+ geom_polygon(fill="pink" )+
+ geom_path(colour = "grey40")+geom_point(x=112.58,y=28.11,fill="black")+
+ annotate("text",x=112.7,y=28,label="长沙") +annotate("text",x=111,y=29,label="湖南省",size=8,colour="blue")+ggtitle("R2-07")
附件