如何用R语言画广东省地图(划分出21个地级市的边界)?

理由
举报 取消

问题描述:除了画出广东省的轮廓,还要画出广东省21个地级市的边界,我按照这篇文章的做法:Editor: R绘制中国地图,并展示流行病学数据画出来的图是这样的:画出来的边界划分太详细了,我试着先画出各个地级市的图,再用ggplot2添加在一起,貌似数据有缺失,请问要怎么画?求大家推荐一些相关文章,或者给一点思路.问题已解决,参见@Allen Shen的回答,感谢各位的关注和回答。

2017年7月23日 4 条回复 1386 次浏览

发起人:unstory 初入职场

回复 ( 4 )

  1. Paul1968
    理由
    举报 取消

    下面是我利用给ggplot2画山东进出口总值地图,2点说明

    1、CHN_adm2.shp是中国行政地图数据表。

    2、ie_price2015.txt是山东各地市进出口数据

    library(ggplot2)

    library(sp)

    library(maps)

    library(mapproj)

    library(maptools)

    library(reshape2)

    library(plyr)

    library(colorspace)

    china_map_x2<-readShapePoly(“E:/学习资料/R/data/map/china/CHN_adm2.shp”)

    shandong3<-subset(china_map_x2,ID_1==594)

    x<-shandong3@data

    shandong_data<-fortify(shandong3)

    ie_price <- read.table(“E:/学习资料/R/data/ie_price2015.txt”,header = TRUE)

    shandong_mapdata<-join (shandong_data, ie_price,type=’inner’)

    mid_range <- function(x) mean(range(x, na.rm = TRUE))

    centres <- ddply(shandong_mapdata, .(ie_price), colwise(mid_range, .(lat, long)))

    mid_range <- function(x) mean(range(x, na.rm = TRUE))

    centres <- ddply(shandong_mapdata, .(ie_price), colwise(mid_range, .(lat, long)))

    p<-ggplot(shandong_mapdata, aes(x = long, y = lat, fill =ie_price))+

    geom_polygon(aes(group = group), colour =”grey60″)+

    geom_text(aes(label = as.character(ie_price)), data = centres, size =+ 3, angle = 30)+

    scale_fill_continuous(low=”ghostwhite”, high=”steelblue”,space = “Lab”, limits=c(50,4500),name=”亿元”)+

    coord_map()+

    labs(title = “2015年前11个月山东省进出口总值分布地图”) +

    xlab(“”)+

    ylab(“”)+

    theme_bw()+

    theme(legend.title = element_text(face = “italic”),legend.position = c(0.9,0.25))+

    theme(panel.grid=element_blank(),panel.border=element_blank(), axis.line=element_line(linetype = “blank”), axis.ticks =element_line(linetype =

    “blank”),axis.text.y = element_blank(),axis.text.x = element_blank())

  2. unstory
    理由
    举报 取消
    library(ggplot2)
    library(maptools)
    #install.packages('ggplot2')
    #install.packages('maptools')
    #install.packages('mapproj')
    y=readShapePoly('CHN_adm2.shp')
    y1=subset(y,y$NAME_1=='Guangdong')
    y1$NAME_2  #按照这个顺序输入你的数据
    gddat=fortify(y1)
    gddat = transform(gddat, id = iconv(id, from = 'GBK'), group = iconv(group, from =  'GBK'))
    names(gddat)[1:2]=c('x','y')
    sub_gddat = data.frame(id = unique(sort(gddat$id)))
    sub_gddat$income=c(21,258,219,601.8,16.55,78.8,73.56,34.03,44.9,27.11,33.5,63.23,9.6481,31.12,548.66,20.856362,16.39,56.19,33.540357,96.92,72.61)
    gdmap = ggplot(sub_gddat) +geom_map(aes(map_id = id, fill = income), color = "white",  map = gddat) +scale_fill_gradient(high = "darkgreen",low = "lightgreen")  +expand_limits(gddat) + coord_map()
    print(gdmap)
    temp=coordinates(y1)
    temp=as.data.frame(temp)
    temp$name=c('潮州','东莞','佛山','广州','河源','惠州','江门','揭阳','茂名','梅州','清远 ','汕头','汕尾','韶关','深圳','阳江','云浮','湛江','肇庆','中山','珠海')
    gdmap + geom_text(aes(x = V1,y = V2,label = name), family = "GB1", data = temp)
    
  3. 用户头像
    理由
    举报 取消

    应该也是作者的帖子,利用这篇博客里的链接下载了作者提供的数据,但是由于注册cos有问题,没能在贴下回复感谢,来这里道一声“谢谢”!

我来回答

Captcha 点击图片更换验证码