如何用R語言畫廣東省地圖(劃分出21個地級市的邊界)?

問題描述:除了畫出廣東省的輪廓,還要畫出廣東省21個地級市的邊界,我按照這篇文章的做法:
Editor: R繪製中國地圖,並展示流行病學數據
畫出來的圖是這樣的:

畫出來的邊界劃分太詳細了,我試著先畫出各個地級市的圖,再用ggplot2添加在一起,貌似數據有缺失,請問要怎麼畫?求大家推薦一些相關文章,或者給一點思路.

問題已解決,參見@Allen Shen的回答,感謝各位的關注和回答。


下面是我利用給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())


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)


http://www.dataguru.cn/thread-346958-1-1.html


http://cos.name/cn/topic/413196/應該也是作者的帖子,利用這篇博客里的鏈接下載了作者提供的數據,但是由於註冊cos有問題,沒能在貼下回復感謝,來這裡道一聲「謝謝」!


推薦閱讀:

好看的數據可視化的圖片是怎麼樣做的?
R語言中,RCurl優勢在哪兒,做爬蟲的話用Python還是RCurl效率高?
如何爬取網頁表格數據?

TAG:數據可視化 | R編程語言 |