install.packages("maptools") #还没安装maptools的执行此语句
library(maptools)
library(rgdal)
str.crs
china
#绘制中国地图
par(mar=c(2,2,0.1,0.1))
plot(china, axes = TRUE)
#给不同省标上不同颜色
province
n
color
for(i in 1:n){
plot(subset(china, slot(china,"data")$NAME==province[i]),
add = TRUE, col=color[i], border="gray")
}
#添加省会城市
capital
cap.name
cap.coords
n
plot(capital, add=TRUE, pch=20, cex=0.8)
set.seed(2000)
pos
spec.name
pos[cap.name%in%spec.name]
spec.name
pos[cap.name%in%spec.name]
text(cap.coords, labels = cap.name, cex = 0.7, pos=pos, offset=0.2)