Skip to content

Instantly share code, notes, and snippets.

@komasaru
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save komasaru/07fa60f41d3b8c288a76 to your computer and use it in GitHub Desktop.
Save komasaru/07fa60f41d3b8c288a76 to your computer and use it in GitHub Desktop.
R script to generate a map by maptools.
# ライブラリの読み込み
library(maptools)
library(RColorBrewer)
# Shape ファイルのフルパス
shp <- '/path/to/shapefile.shp'
# Shape ファイルの読み込み
# map <- readShapePoly(shp) # これでもよい
map <- readShapeSpatial(shp)
# 色設定
#( RColorBrewer - Paired パレット の12色を21市町村分ランダムに設定する例 )
col <- sample(1:12, size=21, replace=T)
# プロット
# ( x, y 軸表示、ラベル「全て水平」、RColorBrewer で塗りつぶし、
# 境界線「青」、境界線太さ「1」 )
plot(map, axes=T, las=1, col=brewer.pal(12,"Paired")[col], border="blue", lwd=1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment