用 R 画中国分省市地图

用 R 画中国分省市地图

  (2010-11-18 16:25:34)
标签: 

中国地图

 

营销

 

杂谈

分类: 数据分析

用R 也可以做出漂亮的依参数变化的中国地图。

主要参考(http://cos.name/author/yixuanq/用 <wbr>R <wbr>画中国分省市地图

 

library(maptools)

axx<-readShapePoly("bou2_4p.shp", proj4string=CRS("+proj=longlat +ellps=clrk66"))

x=axx
#plot(x,col=gray(924:0/924));#using col instead of fg!

 

getColor=function(mapdata,provname,provcol,othercol)
{
 f=function(x,y) ifelse(x %in% y,which(y==x),0);
 colIndex=sapply(mapdata$NAME,f,provname);
 col=c(othercol,provcol)[colIndex+1];
 return(col);
}


provname=c("北京市","天津市","河北省","山西省","内蒙古自治区",
  "辽宁省","吉林省","黑龙江省","上海市","江苏省",
  "浙江省","安徽省","福建省","江西省","山东省",
  "河南省","湖北省","湖南省","广东省",
  "广西壮族自治区","海南省","重庆市","四川省","贵州省",
  "云南省","西藏自治区","陕西省","甘肃省","青海省",
  "宁夏回族自治区","新疆维吾尔自治区","台湾省",
  "香港特别行政区");
pop=c(1633,1115,6943,3393,2405,4298,2730,3824,1858,7625,
  5060,6118,3581,4368,9367,9360,5699,6355,9449,
  4768,845,2816,8127,3762,4514,284,3748,2617,
  552,610,2095,2296,693);
provcol=rgb(red=1-pop/max(pop)/1,green=1-pop/max(pop)/1,blue=1/1.5);
plot(x,col=getColor(x,provname,provcol,"white"),border = "grey",xlab="",ylab="")

posted @ 2014-04-03 20:39  JamesFan  阅读(822)  评论(0编辑  收藏  举报