R2-04 第九期 地图

blanking 2018-01-02 22:42:45 阅读: 1235

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")R2-09-01.png


R2-09-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

微信服务号