服务热线
178 0020 3020
library(ggplot2)
library(plyr)
library(sp)
library(maptools)
#china_map <- st_read("/Users/taowang/documents/R/R2/R2-9/china-province-border-data/bou2_4p.shp")
china_map_1 <- readShapePoly("/Users/taowang/documents/R/R2/R2-9/china-province-border-data/bou2_4p.shp")
china_map_1@data$NAME <- iconv(china_map_1@data$NAME,"GBK","UTF-8")
china_map <- fortify(china_map_1) #几何映射层
china_map_data <- china_map_1@data #描述层
china_map_data <- data.frame(china_map_data, id = seq(0:924)-1)
china <- join(china_map,china_map_data, type="full")
henan <- subset(china,NAME== "河南省")
mytheme <- theme(panel.grid = element_blank(),
panel.background = element_blank(),
axis.line = element_blank(),
axis.text = element_blank(),
axis.title = element_blank(),
axis.ticks = element_blank(),
legend.position = "none")
ggplot(henan, aes(x = long, y = lat, group = group,fill=NAME))+
geom_polygon(fill="pink")+
geom_path(colour = "grey40")+
geom_point(x=114.21,y=36.06)+
geom_text(aes(x=114,y=36,label="安阳"),family='STKaiti')+
geom_point(x=113.65,y=34.76)+
geom_text(aes(x=113.5,y=34.5,label="郑州"),family='STKaiti')+
geom_text(aes(x=114,y=33,label="河南省"),col = "red",cex= 5, family='STKaiti')+
mytheme+
ggtitle("R2-04-Henan-Anyang")
Pop <- read.csv("/Users/taowang/documents/R/R2/R2-9/2.csv", dec = ".",sep = ",",
header = T, encoding = "utf-8")
map_pop <- join(china, Pop, by = "NAME", type = "full")
head(map_pop)
mytheme <- theme(panel.grid = element_blank(),
panel.background = element_blank(),
axis.line = element_blank(),
axis.text = element_blank(),
axis.title = element_blank(),
axis.ticks = element_blank())
ggplot(map_pop, aes(x = long, y = lat, group = group,fill=pop))+
geom_polygon()+
scale_fill_gradient(low = "white",high = "red")+
geom_path(colour = "green")+
mytheme+
ggtitle("R2-04")
附件