1. 程式人生 > >R語言 : 畫中國地圖

R語言 : 畫中國地圖

from http://www.klshu.com/1323.html

china_map.R 程式碼如下

par(mar=rep(0,4))
dat <- read.csv("D:/test/china.csv", header=T)
library(maps)
library(mapdata)
map("china", col = "darkgray", ylim = c(18, 54), panel.first = grid())

points(dat$jd, dat$wd, pch = 19, col = rgb(0, 0, 0, 0.5))

text(dat$jd, dat$wd, dat[, 1], cex = 0.9, col = rgb(0,0, 0, 0.7),
    pos = c(2, 4, 4, 4, 3, 4, 2, 3, 4, 2, 4, 2, 2,
    4, 3, 2, 1, 3, 1, 1, 2, 3, 2, 2, 1, 2, 4, 3, 1, 2, 2, 4, 4, 2))

axis(1, lwd = 0); axis(2, lwd = 0); axis(3, lwd = 0); axis(4, lwd = 0)


china.csv  資料如下
city,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