代码如下:
#东北
db <- c("吉林","辽宁","黑龙江")
#华北
hb <-c("内蒙古","北京","天津","河北","山东","山西")
#华中
hz <- c("河南","湖北","湖南","江西")
#华东
hd <- c("安徽","江苏","上海","福建","浙江")
#华南
hn <- c("广东","广西","海南")
#西南
xn <- c("贵州","云南","四川","重庆","西藏")
#西北
xb <- c("陕西","青海","甘肃","宁夏","新疆")
#进行自定义临近关系
w_cm_cn <- w_cn
ccn <-list(db,hb,hz,hd,hn,xn,xb)
for(area in ccn){
for(i in area){
i_id <-which(cnData$FIRST_NAME == as.character(i))
temp<-c()
for (j in area){
j_id <-which(cnData$FIRST_NAME == as.character(j))
if(i_id != j_id){
temp <- c(temp,as.integer(j_id))
}
}
w_cm_cn[[i_id]] <- temp
}
}
#绘制自定义的临近关系
w_cm_cn_mat <- nb2listw(w_cm_cn, style="W", zero.policy=TRUE)
plot(cnData)
points(map_crd,col='red',pch='*')
plot(w_cm_cn_mat,coords=map_crd, cex=0.1, col="blue", add=T)
定义的绘制结果如下:
mycolors <- colorRampPalette(c("darkgreen", "yellow", "orangered"))(32)
spplot(cnData, zcol="GDP_2009", col.regions=mycolors, main="中国2009年各省GDP")
#############################################
# 自定义七大区域划分:制造东部沿海发达区域 #
#############################################
#东北
db <- c("吉林","辽宁","黑龙江")
#华北
hb <-c("内蒙古","北京","天津","河北","山西")
#华中
hz <- c("河南","湖北","湖南","江西","安徽")
#华东(人为制造华东为东部沿海发达区域)
hd <- c("江苏","上海","福建","浙江","山东","广东")
#华南
hn <- c("广西","海南")
#西南
xn <- c("贵州","云南","四川","重庆","西藏")
#西北
xb <- c("陕西","青海","甘肃","宁夏","新疆")