|
library(maptools);
x=readShapePoly('bou2_4p.shp')
plot(x);
plot(x,col=gray(924:0/924));
getColor=function(mapdata,provname,provcol,othercol)
{
f=function(x,y) ifelse(x %in% y,which(y==x),0);
colIndex=sapply(mapdata@data$NAME,f,provname);
col=c(othercol,provcol)[colIndex+1];
return(col);
}
provname=c("北京市","天津市","河北省","山西省","内蒙古自治区",
"辽宁省","吉林省","黑龙江省","上海市","江苏省",
"浙江省","安徽省","福建省","江西省","山东省",
"河南省","湖北省","湖南省","广东省",
"广西壮族自治区","海南省","重庆市","四川省","贵州省",
"云南省","西藏自治区","陕西省","甘肃省","青海省",
"宁夏回族自治区","新疆维吾尔自治区","台湾省",
"香港特别行政区");
provcol=c("red","green","yellow","green","red","green","yellow","blue","red","green","yellow","blue","red","green","yellow","purple","red","green","yellow","purple","red","green","yellow","blue","red","green","yellow","purple","red","green","yellow","purple","blue","green","yellow","purple","green");
plot(x,col=getColor(x,provname,provcol,"white"),border = "green",xlab="",ylab="")
legend("topleft", legend = provname, bty = "n", col = provcol, pch = 15,ncol = 1, cex = 0.7, lwd = 1)
dat = read.csv(textConnection("省份,jd,wd
北京,116.4666667,39.9
上海,121.4833333,31.23333333
天津,117.1833333,39.15
重庆,106.5333333,29.53333333
黑龙江,126.6833333,45.75
吉林,125.3166667,43.86666667
辽宁,123.4,41.83333333
内蒙,111.8,40.81666667
河北,114.4666667,38.03333333
山西,112.5666667,37.86666667
山东,117,36.63333333
河南,113.7,34.8
陕西,108.9,34.26666667
甘肃,103.8166667,36.05
宁夏,106.2666667,38.33333333
青海,101.75,36.63333333
新疆,87.6,43.8
安徽,117.3,31.85
江苏,118.8333333,32.03333333
浙江,120.15,30.23333333
湖南,113,28.18333333
江西,115.8666667,28.68333333
湖北,114.35,30.61666667
四川,104.0833333,30.65
贵州,106.7,26.58333333
福建,119.3,26.08333333
台湾,121.5166667,25.05
广东,113.25,23.13333333
海南,110.3333333,20.03333333
广西,108.3333333,22.8
云南,102.6833333,25
西藏,91.16666667,29.66666667
香港,114.1666667,22.3
澳门,113.5,22.2"))
text(dat$jd, dat$wd, dat[, 1], cex = 0.7)
# 一个晚上的辛苦成果。
|